66
77use Doctrine \DBAL \Platforms \AbstractPlatform ;
88use MartinGeorgiev \Doctrine \DBAL \Types \BaseNetworkTypeArray ;
9+ use PHPUnit \Framework \Attributes \DataProvider ;
910use PHPUnit \Framework \Attributes \Test ;
1011use PHPUnit \Framework \MockObject \MockObject ;
1112use PHPUnit \Framework \TestCase ;
@@ -55,24 +56,28 @@ public function has_name(): void
5556 }
5657
5758 #[Test]
58- public function can_convert_null_to_database_value (): void
59+ #[DataProvider('provideValidTransformations ' )]
60+ public function can_convert_to_php_value (?array $ phpValue , ?string $ postgresValue ): void
5961 {
60- self ::assertNull ( $ this ->fixture ->convertToDatabaseValue ( null , $ this ->platform ));
62+ self ::assertEquals ( $ phpValue , $ this ->fixture ->convertToPHPValue ( $ postgresValue , $ this ->platform ));
6163 }
6264
63- #[Test]
64- public function can_convert_empty_array_to_database_value (): void
65+ public static function provideValidTransformations (): array
6566 {
66- self ::assertEquals ('{} ' , $ this ->fixture ->convertToDatabaseValue ([], $ this ->platform ));
67- }
68-
69- #[Test]
70- public function can_convert_valid_array_to_database_value (): void
71- {
72- self ::assertEquals (
73- '{"valid_address","valid_address"} ' ,
74- $ this ->fixture ->convertToDatabaseValue (['valid_address ' , 'valid_address ' ], $ this ->platform )
75- );
67+ return [
68+ 'null ' => [
69+ 'phpValue ' => null ,
70+ 'postgresValue ' => null ,
71+ ],
72+ 'empty array ' => [
73+ 'phpValue ' => [],
74+ 'postgresValue ' => '{} ' ,
75+ ],
76+ 'valid array ' => [
77+ 'phpValue ' => ['valid_address ' , 'valid_address ' ],
78+ 'postgresValue ' => '{"valid_address","valid_address"} ' ,
79+ ],
80+ ];
7681 }
7782
7883 #[Test]
@@ -84,23 +89,31 @@ public function throws_exception_for_invalid_type(): void
8489 }
8590
8691 #[Test]
87- public function can_convert_null_to_php_value (): void
92+ #[DataProvider('provideInvalidValues ' )]
93+ public function throws_exception_for_invalid_values (mixed $ arrayItem , string $ exceptionMessage ): void
8894 {
89- self ::assertNull ($ this ->fixture ->convertToPHPValue (null , $ this ->platform ));
95+ $ this ->expectException (\InvalidArgumentException::class);
96+ $ this ->expectExceptionMessage ($ exceptionMessage );
97+ $ this ->fixture ->transformArrayItemForPHP ($ arrayItem );
9098 }
9199
92- #[Test]
93- public function can_convert_empty_array_to_php_value (): void
100+ public static function provideInvalidValues (): array
94101 {
95- self ::assertEquals ([], $ this ->fixture ->convertToPHPValue ('{} ' , $ this ->platform ));
102+ return [
103+ 'invalid type ' => [
104+ 'arrayItem ' => [],
105+ 'exceptionMessage ' => 'Invalid type ' ,
106+ ],
107+ 'invalid format ' => [
108+ 'arrayItem ' => '"invalid_address" ' ,
109+ 'exceptionMessage ' => 'Invalid format ' ,
110+ ],
111+ ];
96112 }
97113
98114 #[Test]
99- public function can_convert_valid_string_to_php_value (): void
115+ public function transform_array_item_for_php_handles_valid_string (): void
100116 {
101- self ::assertEquals (
102- ['valid_address ' , 'valid_address ' ],
103- $ this ->fixture ->convertToPHPValue ('{"valid_address","valid_address"} ' , $ this ->platform )
104- );
117+ $ this ->assertSame ('valid_address ' , $ this ->fixture ->transformArrayItemForPHP ('"valid_address" ' ));
105118 }
106119}
0 commit comments