@@ -29,7 +29,7 @@ public function testInstantiate(): void
29
29
'id ' => 'int ' ,
30
30
'remark ' => 'json ' ,
31
31
];
32
- $ converter = new DataConverter ($ types );
32
+ $ converter = $ this -> createDataConverter ($ types );
33
33
34
34
$ this ->assertInstanceOf (DataConverter::class, $ converter );
35
35
}
@@ -39,7 +39,7 @@ public function testInstantiate(): void
39
39
*/
40
40
public function testConvertDataFromDB (array $ types , array $ dbData , array $ expected ): void
41
41
{
42
- $ converter = new DataConverter ($ types );
42
+ $ converter = $ this -> createDataConverter ($ types );
43
43
44
44
$ data = $ converter ->fromDatabase ($ dbData );
45
45
@@ -51,7 +51,7 @@ public function testConvertDataFromDB(array $types, array $dbData, array $expect
51
51
*/
52
52
public function testConvertDataToDB (array $ types , array $ phpData , array $ expected ): void
53
53
{
54
- $ converter = new DataConverter ($ types );
54
+ $ converter = $ this -> createDataConverter ($ types );
55
55
56
56
$ data = $ converter ->toDatabase ($ phpData );
57
57
@@ -328,7 +328,7 @@ public function testDateTimeConvertDataFromDB(): void
328
328
'id ' => 'int ' ,
329
329
'date ' => 'datetime ' ,
330
330
];
331
- $ converter = new DataConverter ($ types );
331
+ $ converter = $ this -> createDataConverter ($ types );
332
332
333
333
$ dbData = [
334
334
'id ' => '1 ' ,
@@ -347,7 +347,7 @@ public function testDateTimeConvertDataToDB(): void
347
347
'id ' => 'int ' ,
348
348
'date ' => 'datetime ' ,
349
349
];
350
- $ converter = new DataConverter ($ types );
350
+ $ converter = $ this -> createDataConverter ($ types );
351
351
352
352
$ phpData = [
353
353
'id ' => '1 ' ,
@@ -364,7 +364,7 @@ public function testTimestampConvertDataFromDB(): void
364
364
'id ' => 'int ' ,
365
365
'date ' => 'timestamp ' ,
366
366
];
367
- $ converter = new DataConverter ($ types );
367
+ $ converter = $ this -> createDataConverter ($ types );
368
368
369
369
$ dbData = [
370
370
'id ' => '1 ' ,
@@ -382,7 +382,7 @@ public function testTimestampConvertDataToDB(): void
382
382
'id ' => 'int ' ,
383
383
'date ' => 'timestamp ' ,
384
384
];
385
- $ converter = new DataConverter ($ types );
385
+ $ converter = $ this -> createDataConverter ($ types );
386
386
387
387
$ phpData = [
388
388
'id ' => '1 ' ,
@@ -399,7 +399,7 @@ public function testURIConvertDataFromDB(): void
399
399
'id ' => 'int ' ,
400
400
'url ' => 'uri ' ,
401
401
];
402
- $ converter = new DataConverter ($ types );
402
+ $ converter = $ this -> createDataConverter ($ types );
403
403
404
404
$ dbData = [
405
405
'id ' => '1 ' ,
@@ -417,7 +417,7 @@ public function testURIConvertDataToDB(): void
417
417
'id ' => 'int ' ,
418
418
'url ' => 'uri ' ,
419
419
];
420
- $ converter = new DataConverter ($ types );
420
+ $ converter = $ this -> createDataConverter ($ types );
421
421
422
422
$ phpData = [
423
423
'id ' => '1 ' ,
@@ -437,7 +437,7 @@ public function testInvalidType(): void
437
437
'id ' => 'invalid ' ,
438
438
'remark ' => 'json-array ' ,
439
439
];
440
- $ converter = new DataConverter ($ types );
440
+ $ converter = $ this -> createDataConverter ($ types );
441
441
442
442
$ dbData = [
443
443
'id ' => '1 ' ,
@@ -457,12 +457,17 @@ public function testInvalidCastHandler(): void
457
457
'id ' => 'int ' ,
458
458
'remark ' => 'json-array ' ,
459
459
];
460
- $ converter = new DataConverter ($ types , ['int ' => DataConverter::class]);
460
+ $ converter = $ this -> createDataConverter ($ types , ['int ' => DataConverter::class]);
461
461
462
462
$ dbData = [
463
463
'id ' => '1 ' ,
464
464
'remark ' => '{"foo":"bar", "baz":true} ' ,
465
465
];
466
466
$ converter ->fromDatabase ($ dbData );
467
467
}
468
+
469
+ private function createDataConverter (array $ types , array $ handlers = []): DataConverter
470
+ {
471
+ return new DataConverter ($ types , $ handlers );
472
+ }
468
473
}
0 commit comments