Skip to content

Commit

Permalink
test: extract createDataConverter()
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Nov 22, 2023
1 parent 53910de commit 694c4b5
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions tests/system/Database/DataConverter/DataConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testInstantiate(): void
'id' => 'int',
'remark' => 'json',
];
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

$this->assertInstanceOf(DataConverter::class, $converter);
}
Expand All @@ -39,7 +39,7 @@ public function testInstantiate(): void
*/
public function testConvertDataFromDB(array $types, array $dbData, array $expected): void
{
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

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

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

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

Expand Down Expand Up @@ -328,7 +328,7 @@ public function testDateTimeConvertDataFromDB(): void
'id' => 'int',
'date' => 'datetime',
];
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

$dbData = [
'id' => '1',
Expand All @@ -347,7 +347,7 @@ public function testDateTimeConvertDataToDB(): void
'id' => 'int',
'date' => 'datetime',
];
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

$phpData = [
'id' => '1',
Expand All @@ -364,7 +364,7 @@ public function testTimestampConvertDataFromDB(): void
'id' => 'int',
'date' => 'timestamp',
];
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

$dbData = [
'id' => '1',
Expand All @@ -382,7 +382,7 @@ public function testTimestampConvertDataToDB(): void
'id' => 'int',
'date' => 'timestamp',
];
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

$phpData = [
'id' => '1',
Expand All @@ -399,7 +399,7 @@ public function testURIConvertDataFromDB(): void
'id' => 'int',
'url' => 'uri',
];
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

$dbData = [
'id' => '1',
Expand All @@ -417,7 +417,7 @@ public function testURIConvertDataToDB(): void
'id' => 'int',
'url' => 'uri',
];
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

$phpData = [
'id' => '1',
Expand All @@ -437,7 +437,7 @@ public function testInvalidType(): void
'id' => 'invalid',
'remark' => 'json-array',
];
$converter = new DataConverter($types);
$converter = $this->createDataConverter($types);

$dbData = [
'id' => '1',
Expand All @@ -457,12 +457,17 @@ public function testInvalidCastHandler(): void
'id' => 'int',
'remark' => 'json-array',
];
$converter = new DataConverter($types, ['int' => DataConverter::class]);
$converter = $this->createDataConverter($types, ['int' => DataConverter::class]);

$dbData = [
'id' => '1',
'remark' => '{"foo":"bar", "baz":true}',
];
$converter->fromDatabase($dbData);
}

private function createDataConverter(array $types, array $handlers = []): DataConverter
{
return new DataConverter($types, $handlers);
}
}

0 comments on commit 694c4b5

Please sign in to comment.