Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: CI

on:
push:
branches:
- main
paths-ignore:
- '.github/actions/release-please/**'
pull_request:
branches:
- main
Expand All @@ -19,10 +24,10 @@ jobs:
run: |
if [ "${{ github.event.pull_request.user.id }}" = "41898282" ]; then
echo "run=false" >> $GITHUB_OUTPUT
echo "::notice::Skipping CI checks - release-please PR"
echo "::notice::Skipping CI checks - this a release-please bot's interaction"
else
echo "run=true" >> $GITHUB_OUTPUT
echo "::notice::CI checks will execute - the PR author is not the release-please bot"
echo "::notice::CI checks will execute - the actor is not the release-please bot"
fi

tests:
Expand Down
6 changes: 5 additions & 1 deletion ci/phpunit/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
failOnRisky="true"
failOnWarning="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true">
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnPhpunitDeprecations="true">
<testsuites>
<testsuite name="PostgreSQL-for-Doctrine Test Suite">
<directory>../../tests</directory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class BaseFloatArrayTestCase extends TestCase
/**
* @test
*
* @dataProvider provideInvalidTransformations
* @dataProvider provideInvalidPHPValuesForDatabaseTransformation
*/
public function can_detect_invalid_for_transformation_php_value(mixed $phpValue): void
{
Expand All @@ -25,7 +25,7 @@ public function can_detect_invalid_for_transformation_php_value(mixed $phpValue)
/**
* @return list<mixed>
*/
public static function provideInvalidTransformations(): array
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
{
return [
[true],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class BaseIntegerArrayTestCase extends TestCase
/**
* @test
*
* @dataProvider provideInvalidTransformations
* @dataProvider provideInvalidPHPValuesForDatabaseTransformation
*/
public function can_detect_invalid_for_transformation_php_value(mixed $phpValue): void
{
Expand All @@ -25,7 +25,7 @@ public function can_detect_invalid_for_transformation_php_value(mixed $phpValue)
/**
* @return list<mixed>
*/
public static function provideInvalidTransformations(): array
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
{
return [
[true],
Expand Down Expand Up @@ -85,5 +85,5 @@ public function throws_domain_exception_when_value_exceeds_range(string $outOfRa
/**
* @return array<array{string}>
*/
abstract protected function provideOutOfRangeValues(): array;
abstract public static function provideOutOfRangeValues(): array;
}
6 changes: 3 additions & 3 deletions tests/MartinGeorgiev/Doctrine/DBAL/Types/BigIntArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public function has_name(): void
self::assertEquals('bigint[]', $this->fixture->getName());
}

public static function provideInvalidTransformations(): array
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
{
return \array_merge(parent::provideInvalidTransformations(), [
return \array_merge(parent::provideInvalidPHPValuesForDatabaseTransformation(), [
['9223372036854775808'], // Greater than PHP_INT_MAX
['-9223372036854775809'], // Less than PHP_INT_MIN
['1.23e10'], // Scientific notation
Expand Down Expand Up @@ -81,7 +81,7 @@ public function throws_domain_exception_when_value_exceeds_range(string $outOfRa
/**
* @return array<array{string}>
*/
protected function provideOutOfRangeValues(): array
public static function provideOutOfRangeValues(): array
{
return [
['9223372036854775808'], // PHP_INT_MAX + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function can_transform_from_php_value(?array $phpValue, ?string $postgres
*
* @dataProvider provideValidTransformations
*/
public function can_transform_to_php_value(?array $phpValue, ?string $postgresValue): void
public function can_transform_to_php_value(?array $phpValue, ?string $postgresValue, ?array $platformValue = null): void
{
$this->platform->method('convertFromBoolean')
->with($this->anything())
Expand Down
31 changes: 29 additions & 2 deletions tests/MartinGeorgiev/Doctrine/DBAL/Types/CidrArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,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
{
Expand All @@ -96,7 +96,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'],
Expand All @@ -111,4 +111,31 @@ public static function provideInvalidTransformations(): array
'malformed CIDR with spaces' => [['192.168.1.0 / 24']], // Space in CIDR notation
];
}

/**
* @test
*
* @dataProvider provideInvalidDatabaseValuesForPHPTransformationForPHPTransformation
*/
public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(string $postgresValue): void
{
$this->expectException(InvalidCidrArrayItemForPHPException::class);
$this->fixture->convertToPHPValue($postgresValue, $this->platform);
}

/**
* @return array<string, array{string}>
*/
public static function provideInvalidDatabaseValuesForPHPTransformationForPHPTransformation(): array
{
return [
'invalid format' => ['{"invalid-cidr"}'],
'invalid CIDR in array' => ['{"256.256.256.0/24"}'],
'malformed array' => ['not-an-array'],
'empty item in array' => ['{"192.168.1.0/24",""}'],
'invalid item in array' => ['{"192.168.1.0/24","invalid-cidr"}'],
'missing netmask in array' => ['{"192.168.1.0"}'],
'invalid netmask in array' => ['{"192.168.1.0/33"}'],
];
}
}
8 changes: 4 additions & 4 deletions tests/MartinGeorgiev/Doctrine/DBAL/Types/CidrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,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
{
Expand All @@ -113,7 +113,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 [
'empty string' => [''],
Expand All @@ -136,7 +136,7 @@ public static function provideInvalidTransformations(): array
/**
* @test
*
* @dataProvider provideInvalidDatabaseValues
* @dataProvider provideInvalidDatabaseValuesForPHPTransformation
*/
public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(mixed $dbValue): void
{
Expand All @@ -147,7 +147,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_php_va
/**
* @return array<string, array{mixed}>
*/
public static function provideInvalidDatabaseValues(): array
public static function provideInvalidDatabaseValuesForPHPTransformation(): array
{
return [
'invalid type' => [123],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function has_name(): void
self::assertEquals('double precision[]', $this->fixture->getName());
}

public static function provideInvalidTransformations(): array
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
{
return \array_merge(parent::provideInvalidTransformations(), [
return \array_merge(parent::provideInvalidPHPValuesForDatabaseTransformation(), [
['1.7976931348623157E+309'], // Too large
['-1.7976931348623157E+309'], // Too small
['1.123456789012345678'], // Too many decimal places (>15)
Expand Down
34 changes: 32 additions & 2 deletions tests/MartinGeorgiev/Doctrine/DBAL/Types/InetArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'],
Expand All @@ -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
{
Copy link

@coderabbitai coderabbitai bot Apr 11, 2025

Choose a reason for hiding this comment

The 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}>

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Owner Author

Choose a reason for hiding this comment

The 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?

Copy link

Choose a reason for hiding this comment

The 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): void

The parameter is typed as string $postgresValue, so the data provider must return string values. Since all your test cases in the provider return strings (like '{"invalid-ip"}'), the current annotation @return array<string, array{string}> is correct.

The mixed type would only be appropriate if your test method parameter was typed as mixed (like in your other test method).

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
Copy link

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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"}'],
];
}
return [
'non-string value' => [123],
'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"}'],
];
}

}
40 changes: 38 additions & 2 deletions tests/MartinGeorgiev/Doctrine/DBAL/Types/InetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\MartinGeorgiev\Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidInetForDatabaseException;
use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidInetForPHPException;
use MartinGeorgiev\Doctrine\DBAL\Types\Inet;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -109,7 +110,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
{
Expand All @@ -120,9 +121,10 @@ 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 [
'non-string value' => [123],
'empty string' => [''],
'invalid IPv4' => ['256.256.256.256'],
'invalid IPv6' => ['2001:xyz::1'],
Expand All @@ -139,4 +141,38 @@ public static function provideInvalidTransformations(): array
'malformed IPv4-mapped IPv6' => ['::ffff:256.256.256.256'],
];
}

/**
* @test
*
* @dataProvider provideInvalidDatabaseValuesForPHPTransformation
*/
public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(mixed $postgresValue): void
{
$this->expectException(InvalidInetForDatabaseException::class);
$this->fixture->convertToPHPValue($postgresValue, $this->platform);
}

/**
* @return array<string, array{mixed}>
*/
public static function provideInvalidDatabaseValuesForPHPTransformation(): array
{
return [
'non-string value' => [123],
'invalid IPv4' => ['256.256.256.256'],
'invalid IPv6' => ['2001:xyz::1'],
'invalid CIDR format' => ['192.168.1.0/xyz'],
'invalid IPv4 CIDR netmask' => ['192.168.1.0/33'],
'invalid IPv6 CIDR netmask' => ['2001:db8::/129'],
'wrong format' => ['not-an-ip-address'],
'incomplete IPv4' => ['192.168.1'],
'incomplete IPv6' => ['2001:db8'],
'IPv6 too many segments' => ['2001:db8:1:2:3:4:5:6:7'],
'IPv6 invalid segment length' => ['2001:db8:xyz:1:1:1:1:1'],
'IPv4 with invalid octet count' => ['192.168.1'],
'IPv4 with character suffix' => ['192.168.1.1x'],
'malformed IPv4-mapped IPv6' => ['::ffff:256.256.256.256'],
];
}
}
6 changes: 3 additions & 3 deletions tests/MartinGeorgiev/Doctrine/DBAL/Types/IntegerArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function has_name(): void
self::assertEquals('integer[]', $this->fixture->getName());
}

public static function provideInvalidTransformations(): array
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
{
return \array_merge(parent::provideInvalidTransformations(), [
return \array_merge(parent::provideInvalidPHPValuesForDatabaseTransformation(), [
['2147483648'], // Greater than max integer
['-2147483649'], // Less than min integer
['1.23e6'], // Scientific notation
Expand Down Expand Up @@ -67,7 +67,7 @@ public static function provideValidTransformations(): array
/**
* @return array<array{string}>
*/
protected function provideOutOfRangeValues(): array
public static function provideOutOfRangeValues(): array
{
return [
['2147483648'], // MAX_INTEGER + 1
Expand Down
8 changes: 4 additions & 4 deletions tests/MartinGeorgiev/Doctrine/DBAL/Types/JsonbArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function provideValidTransformations(): array
return [
[
'phpValue' => null,
'postgresJsonb' => null,
'postgresValue' => null,
],
[
'phpValue' => [],
Expand All @@ -85,15 +85,15 @@ public static function provideValidTransformations(): array
'key5' => [304, 404, 504, 604],
],
],
'postgresJsonb' => '{{"key1":"value1","key2":false,"key3":"15","key4":15,"key5":[112,242,309,310]},{"key1":"value2","key2":true,"key3":"115","key4":115,"key5":[304,404,504,604]}}',
'postgresValue' => '{{"key1":"value1","key2":false,"key3":"15","key4":15,"key5":[112,242,309,310]},{"key1":"value2","key2":true,"key3":"115","key4":115,"key5":[304,404,504,604]}}',
],
];
}

/**
* @test
*
* @dataProvider provideInvalidTransformations
* @dataProvider provideInvalidPHPValuesForDatabaseTransformation
*/
public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(string $postgresValue): void
{
Expand All @@ -106,7 +106,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_php_va
/**
* @return array<string, array{string}>
*/
public static function provideInvalidTransformations(): array
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
{
return [
'non-array json' => ['"a string encoded as json"'],
Expand Down
Loading
Loading