Skip to content

Commit 120f3dd

Browse files
feat: add the missing support for null values in the network array data types
1 parent e711626 commit 120f3dd

7 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/MartinGeorgiev/Doctrine/DBAL/Types/BaseNetworkTypeArray.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ protected function transformArrayItemForPostgres(mixed $item): string
3333

3434
public function isValidArrayItemForDatabase(mixed $item): bool
3535
{
36+
if ($item === null) {
37+
return true;
38+
}
39+
3640
if (!\is_string($item)) {
3741
return false;
3842
}
@@ -42,7 +46,7 @@ public function isValidArrayItemForDatabase(mixed $item): bool
4246

4347
public function transformArrayItemForPHP(mixed $item): ?string
4448
{
45-
if ($item === null) {
49+
if ($item === null || $item === 'NULL') {
4650
return null;
4751
}
4852

tests/Integration/MartinGeorgiev/Doctrine/DBAL/Types/CidrArrayTypeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function can_handle_array_values(string $testName, array $arrayValue): vo
2828
}
2929

3030
/**
31-
* @return array<string, array{string, array<int, string>}>
31+
* @return array<string, array{string, array<int, string|null>}>
3232
*/
3333
public static function provideValidTransformations(): array
3434
{
@@ -47,6 +47,7 @@ public static function provideValidTransformations(): array
4747
'2001:db8::1/128',
4848
]],
4949
'empty cidr array' => ['empty cidr array', []],
50+
'cidr array with null item' => ['cidr array with null item', ['192.168.0.0/24', null, '10.0.0.0/8']],
5051
];
5152
}
5253

tests/Integration/MartinGeorgiev/Doctrine/DBAL/Types/InetArrayTypeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function can_handle_array_values(string $testName, array $arrayValue): vo
2828
}
2929

3030
/**
31-
* @return array<string, array{string, array<int, string>}>
31+
* @return array<string, array{string, array<int, string|null>}>
3232
*/
3333
public static function provideValidTransformations(): array
3434
{
@@ -46,6 +46,7 @@ public static function provideValidTransformations(): array
4646
'::1',
4747
]],
4848
'empty inet array' => ['empty inet array', []],
49+
'inet array with null item' => ['inet array with null item', ['192.168.1.1', null, '10.0.0.1']],
4950
];
5051
}
5152

tests/Integration/MartinGeorgiev/Doctrine/DBAL/Types/MacaddrArrayTypeTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function can_handle_array_values(string $testName, array $arrayValue): vo
2828
}
2929

3030
/**
31-
* @return array<string, array{string, array<int, string>}>
31+
* @return array<string, array{string, array<int, string|null>}>
3232
*/
3333
public static function provideValidTransformations(): array
3434
{
@@ -44,6 +44,7 @@ public static function provideValidTransformations(): array
4444
'0a:0b:0c:0d:0e:0f',
4545
]],
4646
'empty macaddr array' => ['empty macaddr array', []],
47+
'macaddr array with null item' => ['macaddr array with null item', ['08:00:2b:01:02:03', null, '00:11:22:33:44:55']],
4748
];
4849
}
4950

tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/CidrArrayTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public static function provideInvalidDatabaseValueInputs(): array
102102
'empty string' => [['']],
103103
'whitespace only' => [[' ']],
104104
'malformed CIDR with spaces' => [['192.168.1.0 / 24']],
105-
'valid value mixed with null array item' => [['192.168.1.0/24', null]],
106105
'valid value mixed with integer array item' => [['192.168.1.0/24', 123]],
107106
'valid value mixed with boolean array item' => [['192.168.1.0/24', true]],
108107
'valid value mixed with object array item' => [['192.168.1.0/24', new \stdClass()]],
@@ -168,6 +167,7 @@ public static function provideValidArrayItemsForDatabase(): array
168167
'IPv6 CIDR' => ['2001:db8::/32'],
169168
'IPv4 host CIDR' => ['10.0.0.1/32'],
170169
'IPv6 host CIDR' => ['::1/128'],
170+
'null' => [null],
171171
];
172172
}
173173

@@ -187,7 +187,6 @@ public static function provideInvalidArrayItemsForDatabase(): array
187187
'invalid CIDR' => ['invalid-cidr'],
188188
'IP without netmask' => ['192.168.1.0'],
189189
'integer' => [123],
190-
'null' => [null],
191190
'empty string' => [''],
192191
'boolean' => [true],
193192
];

tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/InetArrayTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public static function provideValidArrayItemsForDatabase(): array
194194
'IPv6 CIDR' => ['2001:db8::/32'],
195195
'loopback IPv4' => ['127.0.0.1'],
196196
'loopback IPv6' => ['::1'],
197+
'null' => [null],
197198
];
198199
}
199200

@@ -213,7 +214,6 @@ public static function provideInvalidArrayItemsForDatabase(): array
213214
'invalid IP' => ['invalid-ip'],
214215
'out of range IPv4' => ['256.256.256.256'],
215216
'integer' => [123],
216-
'null' => [null],
217217
'empty string' => [''],
218218
'boolean' => [true],
219219
];

tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/MacaddrArrayTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public static function provideValidArrayItemsForDatabase(): array
170170
'colon separated mixed case' => ['00:0c:29:Aa:Bb:CC'],
171171
'all zeros' => ['00:00:00:00:00:00'],
172172
'all ones' => ['ff:ff:ff:ff:ff:ff'],
173+
'null' => [null],
173174
];
174175
}
175176

@@ -189,7 +190,6 @@ public static function provideInvalidArrayItemsForDatabase(): array
189190
'invalid MAC' => ['invalid-mac'],
190191
'too short' => ['00:11:22:33:44'],
191192
'integer' => [123],
192-
'null' => [null],
193193
'empty string' => [''],
194194
'boolean' => [true],
195195
];

0 commit comments

Comments
 (0)