Skip to content

Commit 98bdf61

Browse files
committed
test: turn MySQLi $strictOn to true by default
1 parent 9357570 commit 98bdf61

File tree

7 files changed

+133
-147
lines changed

7 files changed

+133
-147
lines changed

app/Config/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Database extends Config
177177
'swapPre' => '',
178178
'encrypt' => false,
179179
'compress' => false,
180-
'strictOn' => false,
180+
'strictOn' => true,
181181
'failover' => [],
182182
'port' => 3306,
183183
'foreignKeys' => true,

tests/_support/Config/Registrar.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Registrar
4141
'swapPre' => '',
4242
'encrypt' => false,
4343
'compress' => false,
44-
'strictOn' => false,
44+
'strictOn' => true,
4545
'failover' => [],
4646
'port' => 3306,
4747
],
@@ -60,7 +60,7 @@ class Registrar
6060
'swapPre' => '',
6161
'encrypt' => false,
6262
'compress' => false,
63-
'strictOn' => false,
63+
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
6464
'failover' => [],
6565
'port' => 5432,
6666
],
@@ -79,7 +79,7 @@ class Registrar
7979
'swapPre' => '',
8080
'encrypt' => false,
8181
'compress' => false,
82-
'strictOn' => false,
82+
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
8383
'failover' => [],
8484
'port' => 3306,
8585
'foreignKeys' => true,
@@ -100,7 +100,7 @@ class Registrar
100100
'swapPre' => '',
101101
'encrypt' => false,
102102
'compress' => false,
103-
'strictOn' => false,
103+
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
104104
'failover' => [],
105105
'port' => 1433,
106106
],
@@ -119,7 +119,7 @@ class Registrar
119119
'swapPre' => '',
120120
'encrypt' => false,
121121
'compress' => false,
122-
'strictOn' => false,
122+
'strictOn' => true, // @todo 4.7.0 to remove in v4.8.0
123123
'failover' => [],
124124
],
125125
];

tests/_support/Database/Seeds/CITestSeeder.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class CITestSeeder extends Seeder
1919
{
2020
public function run(): void
2121
{
22-
// Job Data
2322
$data = [
2423
'user' => [
2524
[
@@ -147,7 +146,8 @@ public function run(): void
147146
],
148147
];
149148

150-
// set SQL times to more correct format
149+
// Normalize formats and remove unsupported types for each database driver
150+
151151
if ($this->db->DBDriver === 'SQLite3') {
152152
$data['type_test'][0]['type_date'] = '2020/01/11';
153153
$data['type_test'][0]['type_time'] = '15:22:00';
@@ -157,7 +157,15 @@ public function run(): void
157157

158158
if ($this->db->DBDriver === 'Postgre') {
159159
$data['type_test'][0]['type_time'] = '15:22:00';
160-
$data['type_test'][0]['type_boolean'] = true;
160+
$data['type_test'][0]['type_boolean'] = true; // PostgreSQL has native boolean type
161+
162+
$data['ci_sessions'][] = [
163+
'id' => 'ci_session:1f5o06b43phsnnf8if6bo33b635e4p2o',
164+
'ip_address' => '127.0.0.1',
165+
'timestamp' => '2021-06-25 21:54:14.991403+02',
166+
'data' => '\x' . bin2hex('__ci_last_regenerate|i:1624650854;_ci_previous_url|s:40:\"http://localhost/index.php/home/index\";'),
167+
];
168+
161169
unset(
162170
$data['type_test'][0]['type_enum'],
163171
$data['type_test'][0]['type_set'],
@@ -185,6 +193,11 @@ public function run(): void
185193
}
186194

187195
if ($this->db->DBDriver === 'MySQLi') {
196+
$data['type_test'][0]['type_time'] = '15:22:00';
197+
$data['type_test'][0]['type_date'] = '2020-01-11';
198+
$data['type_test'][0]['type_datetime'] = '2020-06-18 05:12:24';
199+
$data['type_test'][0]['type_timestamp'] = '2019-07-18 21:53:21';
200+
188201
$data['ci_sessions'][] = [
189202
'id' => 'ci_session:1f5o06b43phsnnf8if6bo33b635e4p2o',
190203
'ip_address' => '127.0.0.1',
@@ -193,29 +206,22 @@ public function run(): void
193206
];
194207
}
195208

196-
if ($this->db->DBDriver === 'Postgre') {
197-
$data['ci_sessions'][] = [
198-
'id' => 'ci_session:1f5o06b43phsnnf8if6bo33b635e4p2o',
199-
'ip_address' => '127.0.0.1',
200-
'timestamp' => '2021-06-25 21:54:14.991403+02',
201-
'data' => '\x' . bin2hex('__ci_last_regenerate|i:1624650854;_ci_previous_url|s:40:\"http://localhost/index.php/home/index\";'),
202-
];
203-
}
204-
205209
if ($this->db->DBDriver === 'OCI8') {
206210
$this->db->query('alter session set NLS_DATE_FORMAT=?', ['YYYY-MM-DD HH24:MI:SS']);
211+
207212
$data['type_test'][0]['type_date'] = '2020-01-11 22:11:00';
208213
$data['type_test'][0]['type_time'] = '2020-07-18 15:22:00';
209214
$data['type_test'][0]['type_datetime'] = '2020-06-18 05:12:24';
210215
$data['type_test'][0]['type_timestamp'] = '2020-06-18 21:53:21';
216+
211217
unset($data['type_test'][0]['type_blob']);
212218
}
213219

214-
foreach ($data as $table => $dummyData) {
220+
foreach ($data as $table => $seeds) {
215221
$this->db->table($table)->truncate();
216222

217-
foreach ($dummyData as $singleDummyData) {
218-
$this->db->table($table)->insert($singleDummyData);
223+
foreach ($seeds as $seed) {
224+
$this->db->table($table)->insert($seed);
219225
}
220226
}
221227
}

tests/system/Database/Live/ForgeTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,10 @@ public function testAddTextColumnWithConstraint(): void
16211621
$this->forge->addColumn('user', [
16221622
'text_with_constraint' => ['type' => 'nvarchar(max)', 'default' => ''],
16231623
]);
1624+
} elseif (in_array($this->db->DBDriver, ['MySQLi', 'Postgre', 'SQLite3'], true)) {
1625+
$this->forge->addColumn('user', [
1626+
'text_with_constraint' => ['type' => 'text'],
1627+
]);
16241628
} else {
16251629
$this->forge->addColumn('user', [
16261630
'text_with_constraint' => ['type' => 'text', 'constraint' => 255, 'default' => ''],

tests/system/Database/Live/InsertTest.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ final class InsertTest extends CIUnitTestCase
3030
{
3131
use DatabaseTestTrait;
3232

33-
/**
34-
* @var Forge
35-
*/
36-
public $forge;
37-
38-
protected $refresh = true;
39-
protected $seed = CITestSeeder::class;
33+
protected $seed = CITestSeeder::class;
34+
private Forge $forge;
4035

4136
public function testInsert(): void
4237
{
@@ -93,26 +88,10 @@ public function testInsertBatchFailed(): void
9388
{
9489
$this->expectException(DatabaseException::class);
9590

96-
$data = [
97-
[
98-
'name' => 'Grocery Sales',
99-
],
100-
[
101-
'name' => null,
102-
],
103-
];
104-
105-
$db = $this->db;
106-
107-
if ($this->db->DBDriver === 'MySQLi') {
108-
// strict mode is required for MySQLi to throw an exception here
109-
$config = config('Database');
110-
$config->tests['strictOn'] = true;
111-
112-
$db = Database::connect($config->tests);
113-
}
114-
115-
$db->table('job')->insertBatch($data);
91+
$this->db->table('job')->insertBatch([
92+
['name' => 'Grocery Sales'],
93+
['name' => null],
94+
]);
11695
}
11796

11897
public function testReplaceWithNoMatchingData(): void

0 commit comments

Comments
 (0)