Skip to content

Commit 1fbd6cb

Browse files
authored
Merge pull request #53 from albertcht/master
[Fix] fix wrong values of type boolean
2 parents 063d73f + 86a183c commit 1fbd6cb

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

src/Common/Common.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public static function mysql_escape($fieldValue)
1616
return array_map(__METHOD__, $fieldValue);
1717
}
1818

19+
if (is_bool($fieldValue)) {
20+
return (int) $fieldValue;
21+
}
22+
1923
if (!empty($fieldValue) && is_string($fieldValue)) {
2024
return str_replace(
2125
['\\', "\0", "\n", "\r", "'", '"', "\x1a"],

tests/BatchInsertTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class BatchInsertTest extends BootstrapDatabase
1111
'password',
1212
'name',
1313
'status',
14+
'is_vip'
1415
];
1516

1617
public function testBatchInsertWithFacade()
@@ -20,19 +21,22 @@ public function testBatchInsertWithFacade()
2021
'djunehor@gmail.com',
2122
bcrypt('djunehor'),
2223
'djunehor',
23-
'active'
24+
'active',
25+
true,
2426
],
2527
[
2628
'samuel@gmail.com',
2729
bcrypt('samuel'),
2830
'samuel',
29-
'whodey'
31+
'whodey',
32+
false,
3033
],
3134
[
3235
'general@gmail.com',
3336
bcrypt('general'),
3437
'general',
3538
'inactive',
39+
false,
3640
]
3741
];
3842
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query
@@ -59,12 +63,13 @@ public function testBatchInsertIncorrectColumnCount()
5963
'djunehor@gmail.com',
6064
bcrypt('djunehor'),
6165
'djunehor',
66+
'active',
6267
],
6368
[
6469
'samuel@gmail.com',
6570
bcrypt('samuel'),
6671
'samuel',
67-
'whodey'
72+
'whodey',
6873
],
6974
[
7075
'general@gmail.com',
@@ -86,19 +91,22 @@ public function testBatchInsertWithHelper()
8691
'djunehor@gmail.com',
8792
bcrypt('djunehor'),
8893
'djunehor',
89-
'active'
94+
'active',
95+
true,
9096
],
9197
[
9298
'samuel@gmail.com',
9399
bcrypt('samuel'),
94100
'samuel',
95-
'whodey'
101+
'whodey',
102+
false,
96103
],
97104
[
98105
'general@gmail.com',
99106
bcrypt('general'),
100107
'general',
101108
'inactive',
109+
false,
102110
]
103111
];
104112
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query

tests/BatchUpdateTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class BatchUpdateTest extends BootstrapDatabase
1212
'password',
1313
'name',
1414
'status',
15+
'is_vip',
1516
];
1617

1718
private function insert()
@@ -21,19 +22,22 @@ private function insert()
2122
'djunehor@gmail.com',
2223
bcrypt('djunehor'),
2324
'djunehor',
24-
'active'
25+
'active',
26+
true,
2527
],
2628
[
2729
'samuel@gmail.com',
2830
bcrypt('samuel'),
2931
'samuel',
30-
'whodey'
32+
'whodey',
33+
false,
3134
],
3235
[
3336
'general@gmail.com',
3437
bcrypt('general'),
3538
'general',
3639
'inactive',
40+
false,
3741
]
3842
];
3943
$batchSize = 500; // insert 500 (default), 100 minimum rows in one query
@@ -51,7 +55,8 @@ public function testBatchUpdateWithFacade()
5155
$columnValues = [
5256
[
5357
'id' => 1,
54-
'status' => 'amala'
58+
'name' => 'amala',
59+
'is_vip' => false
5560
],
5661
[
5762
'id' => 2,
@@ -68,7 +73,12 @@ public function testBatchUpdateWithFacade()
6873

6974
$result = Batch::update($this->model, $columnValues, $index);
7075

76+
$member = $this->model->findOrFail(1);
77+
7178
$this->assertTrue($result === 3);
79+
$this->assertEquals('amala', $member->name);
80+
$this->assertFalse($member->is_vip);
81+
7282
$this->model->truncate();
7383
}
7484

@@ -78,7 +88,8 @@ public function testBatchUpdateWithHelper()
7888
$columnValues = [
7989
[
8090
'id' => 1,
81-
'status' => 'amala'
91+
'name' => 'amala',
92+
'is_vip' => false
8293
],
8394
[
8495
'id' => 2,
@@ -95,7 +106,12 @@ public function testBatchUpdateWithHelper()
95106

96107
$result = batch()->update($this->model, $columnValues, $index);
97108

109+
$member = $this->model->findOrFail(1);
110+
98111
$this->assertTrue($result === 3);
112+
$this->assertEquals('amala', $member->name);
113+
$this->assertFalse($member->is_vip);
114+
99115
$this->model->truncate();
100116
}
101117
}

tests/TestModel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ class TestModel extends \Illuminate\Database\Eloquent\Model
44
{
55
protected $table = 'HmKTjCJgLN9bBq7KXzI3';
66

7+
protected $casts = [
8+
'is_vip' => 'boolean'
9+
];
10+
711
/**
812
* Get name of the table.
913
*

0 commit comments

Comments
 (0)