Skip to content

Commit 694c4b5

Browse files
committed
test: extract createDataConverter()
1 parent 53910de commit 694c4b5

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/system/Database/DataConverter/DataConverterTest.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testInstantiate(): void
2929
'id' => 'int',
3030
'remark' => 'json',
3131
];
32-
$converter = new DataConverter($types);
32+
$converter = $this->createDataConverter($types);
3333

3434
$this->assertInstanceOf(DataConverter::class, $converter);
3535
}
@@ -39,7 +39,7 @@ public function testInstantiate(): void
3939
*/
4040
public function testConvertDataFromDB(array $types, array $dbData, array $expected): void
4141
{
42-
$converter = new DataConverter($types);
42+
$converter = $this->createDataConverter($types);
4343

4444
$data = $converter->fromDatabase($dbData);
4545

@@ -51,7 +51,7 @@ public function testConvertDataFromDB(array $types, array $dbData, array $expect
5151
*/
5252
public function testConvertDataToDB(array $types, array $phpData, array $expected): void
5353
{
54-
$converter = new DataConverter($types);
54+
$converter = $this->createDataConverter($types);
5555

5656
$data = $converter->toDatabase($phpData);
5757

@@ -328,7 +328,7 @@ public function testDateTimeConvertDataFromDB(): void
328328
'id' => 'int',
329329
'date' => 'datetime',
330330
];
331-
$converter = new DataConverter($types);
331+
$converter = $this->createDataConverter($types);
332332

333333
$dbData = [
334334
'id' => '1',
@@ -347,7 +347,7 @@ public function testDateTimeConvertDataToDB(): void
347347
'id' => 'int',
348348
'date' => 'datetime',
349349
];
350-
$converter = new DataConverter($types);
350+
$converter = $this->createDataConverter($types);
351351

352352
$phpData = [
353353
'id' => '1',
@@ -364,7 +364,7 @@ public function testTimestampConvertDataFromDB(): void
364364
'id' => 'int',
365365
'date' => 'timestamp',
366366
];
367-
$converter = new DataConverter($types);
367+
$converter = $this->createDataConverter($types);
368368

369369
$dbData = [
370370
'id' => '1',
@@ -382,7 +382,7 @@ public function testTimestampConvertDataToDB(): void
382382
'id' => 'int',
383383
'date' => 'timestamp',
384384
];
385-
$converter = new DataConverter($types);
385+
$converter = $this->createDataConverter($types);
386386

387387
$phpData = [
388388
'id' => '1',
@@ -399,7 +399,7 @@ public function testURIConvertDataFromDB(): void
399399
'id' => 'int',
400400
'url' => 'uri',
401401
];
402-
$converter = new DataConverter($types);
402+
$converter = $this->createDataConverter($types);
403403

404404
$dbData = [
405405
'id' => '1',
@@ -417,7 +417,7 @@ public function testURIConvertDataToDB(): void
417417
'id' => 'int',
418418
'url' => 'uri',
419419
];
420-
$converter = new DataConverter($types);
420+
$converter = $this->createDataConverter($types);
421421

422422
$phpData = [
423423
'id' => '1',
@@ -437,7 +437,7 @@ public function testInvalidType(): void
437437
'id' => 'invalid',
438438
'remark' => 'json-array',
439439
];
440-
$converter = new DataConverter($types);
440+
$converter = $this->createDataConverter($types);
441441

442442
$dbData = [
443443
'id' => '1',
@@ -457,12 +457,17 @@ public function testInvalidCastHandler(): void
457457
'id' => 'int',
458458
'remark' => 'json-array',
459459
];
460-
$converter = new DataConverter($types, ['int' => DataConverter::class]);
460+
$converter = $this->createDataConverter($types, ['int' => DataConverter::class]);
461461

462462
$dbData = [
463463
'id' => '1',
464464
'remark' => '{"foo":"bar", "baz":true}',
465465
];
466466
$converter->fromDatabase($dbData);
467467
}
468+
469+
private function createDataConverter(array $types, array $handlers = []): DataConverter
470+
{
471+
return new DataConverter($types, $handlers);
472+
}
468473
}

0 commit comments

Comments
 (0)