forked from mavinoo/laravelBatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchUpdateTest.php
98 lines (88 loc) · 2.33 KB
/
BatchUpdateTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
require_once ('BootstrapDatabase.php');
use Carbon\Carbon;
class BatchUpdateTest extends BootstrapDatabase
{
public $columns = [
'email',
'password',
'name',
'status',
];
private function insert()
{
$values = [
[
bcrypt('djunehor'),
'djunehor',
'active'
],
[
bcrypt('samuel'),
'samuel',
'whodey'
],
[
bcrypt('general'),
'general',
'inactive',
]
];
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query
$result = Batch::insert($this->model, $this->columns, $values, $batchSize);
$this->assertIsArray($result);
$this->assertTrue($result['totalRows'] == 3);
$this->assertTrue($result['totalBatch'] == 500);
}
public function testBatchUpdateWithFacade()
{
$this->insert();
$columnValues = [
[
'id' => 1,
'status' => 'amala'
],
[
'id' => 2,
'status' => 'deactive',
'name' => 'Ghanbari'
],
[
'id' => 3,
'status' => 'active',
'created_at' => Carbon::now()
]
];
$index = 'id';
$result = Batch::update($this->model, $columnValues, $index);
$this->assertTrue($result == 3);
$this->model->truncate();
}
public function testBatchUpdateWithHelper()
{
$this->insert();
$columnValues = [
[
'id' => 1,
'status' => 'amala'
],
[
'id' => 2,
'status' => 'deactive',
'name' => 'Ghanbari'
],
[
'id' => 3,
'status' => 'active',
'created_at' => Carbon::now()
]
];
$index = 'id';
$result = batch()->update($this->model, $columnValues, $index);
$this->assertTrue($result == 3);
$this->model->truncate();
}
}