-
-
Notifications
You must be signed in to change notification settings - Fork 56
chore: improve tests #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: improve tests #340
Changes from all commits
71facac
11eadd7
36e640b
1d559f3
1633f90
d56f1f0
0403aed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -105,7 +105,7 @@ public static function provideValidTransformations(): array | |||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @test | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @dataProvider provideInvalidTransformations | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @dataProvider provideInvalidPHPValuesForDatabaseTransformation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function throws_exception_when_invalid_data_provided_to_convert_to_database_value(mixed $phpValue): void | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -116,7 +116,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_databa | |||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return array<string, array{mixed}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static function provideInvalidTransformations(): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static function provideInvalidPHPValuesForDatabaseTransformation(): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'invalid type' => ['not-an-array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -136,4 +136,34 @@ public static function provideInvalidTransformations(): array | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 'IPv6 with invalid segment length' => [['2001:db8:xyz:1:1:1:1:1']], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @test | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @dataProvider provideInvalidDatabaseValuesForPHPTransformation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(string $postgresValue): void | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->expectException(InvalidInetArrayItemForPHPException::class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| $this->fixture->convertToPHPValue($postgresValue, $this->platform); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return array<string, array{string}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static function provideInvalidDatabaseValuesForPHPTransformation(): array | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Return type annotation should allow for mixed values. The current return type annotation only allows for string values, but to test non-string inputs, it should allow for mixed values. - @return array<string, array{string}>
+ @return array<string, array{mixed}>
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't be correct based on the provider data, and PHPStan will scream at you. Or maybe not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @martin-georgiev You're absolutely right. The suggestion to change to `array <string, array{mixed}>` would be incorrect and PHPStan would indeed flag it. Looking at your test method: public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(string $postgresValue): voidThe parameter is typed as The |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'invalid format' => ['{"invalid-ip"}'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'invalid IPv4 in array' => ['{"256.256.256.256"}'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'invalid IPv6 in array' => ['{"2001:xyz::1"}'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'malformed array' => ['not-an-array'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'empty item in array' => ['{"192.168.1.1",""}'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'invalid item in array' => ['{"192.168.1.1","invalid-ip"}'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'invalid CIDR in array' => ['{"192.168.1.0/33"}'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'incomplete IPv4 in array' => ['{"192.168.1"}'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'incomplete IPv6 in array' => ['{"2001:db8"}'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+157
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add non-string test case to match parameter type change. To fully test invalid inputs, consider adding a non-string test case similar to the one in InetTest. return [
+ 'non-string value' => [123],
'invalid format' => ['{"invalid-ip"}'],
'invalid IPv4 in array' => ['{"256.256.256.256"}'],
// ...existing test cases...
];📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.