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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static function provideValidTransformations(): array
}

#[Test]
public function throws_invalid_argument_exception_when_php_value_is_not_array(): void
public function throws_exception_when_php_value_is_not_array(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/Given PHP value content type is not PHP array. Instead it is "\w+"./');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class BaseFloatArrayTestCase extends TestCase
{
protected BaseFloatArray $fixture;

#[DataProvider('provideInvalidPHPValuesForDatabaseTransformation')]
#[DataProvider('provideInvalidDatabaseValueInputs')]
#[Test]
public function can_detect_invalid_for_transformation_php_value(mixed $phpValue): void
{
Expand All @@ -24,7 +24,7 @@ public function can_detect_invalid_for_transformation_php_value(mixed $phpValue)
/**
* @return list<mixed>
*/
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
public static function provideInvalidDatabaseValueInputs(): array
{
return [
[true],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class BaseIntegerArrayTestCase extends TestCase
{
protected BaseIntegerArray $fixture;

#[DataProvider('provideInvalidPHPValuesForDatabaseTransformation')]
#[DataProvider('provideInvalidDatabaseValueInputs')]
#[Test]
public function can_detect_invalid_for_transformation_php_value(mixed $phpValue): void
{
Expand All @@ -24,7 +24,7 @@ public function can_detect_invalid_for_transformation_php_value(mixed $phpValue)
/**
* @return list<mixed>
*/
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
public static function provideInvalidDatabaseValueInputs(): array
{
return [
[true],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function has_name(): void

#[Test]
#[DataProvider('provideValidTransformations')]
public function can_convert_to_php_value(?array $phpValue, ?string $postgresValue): void
public function can_transform_to_php_value(?array $phpValue, ?string $postgresValue): void
{
self::assertEquals($phpValue, $this->fixture->convertToPHPValue($postgresValue, $this->platform));
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public static function provideInvalidValues(): array
}

#[Test]
public function transform_array_item_for_php_handles_valid_string(): void
public function can_transform_array_item_for_php_with_valid_string(): void
{
$this->assertSame('valid_address', $this->fixture->transformArrayItemForPHP('"valid_address"'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,48 @@ public function can_handle_empty_string_from_sql(): void
self::assertNull($result);
}

#[DataProvider('provideInvalidDatabaseValues')]
#[Test]
public function throws_exception_for_invalid_php_value_type(): void
public function throws_exception_for_invalid_database_value_inputs(mixed $invalidValue): void
{
$this->expectException(InvalidRangeForDatabaseException::class);
$this->expectExceptionMessage('Invalid type for range');

$this->fixture->convertToDatabaseValue('invalid', $this->platform); // @phpstan-ignore-line argument.type
$this->fixture->convertToDatabaseValue($invalidValue, $this->platform); // @phpstan-ignore-line argument.type
}

/**
* @return array<string, array{mixed}>
*/
public static function provideInvalidDatabaseValues(): array
{
return [
'string value' => ['not_a_range'],
'integer value' => [123],
'array value' => [[1, 2, 3]],
];
}

#[DataProvider('provideInvalidPHPValues')]
#[Test]
public function throws_exception_for_invalid_sql_value_type(): void
public function throws_exception_for_invalid_php_value_inputs(mixed $invalidValue): void
{
$this->expectException(InvalidRangeForPHPException::class);
$this->expectExceptionMessage('Invalid database value type for range conversion');

$this->fixture->convertToPHPValue([1, 2], $this->platform); // @phpstan-ignore-line argument.type
$this->fixture->convertToPHPValue($invalidValue, $this->platform); // @phpstan-ignore-line argument.type
}

/**
* @return array<string, array{mixed}>
*/
public static function provideInvalidPHPValues(): array
{
return [
'integer value' => [123],
'array value' => [['invalid']],
'boolean value' => [true],
];
}

#[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function throws_exception_when_getting_sql_declaration_with_no_type_name(
}

#[Test]
public function returns_correct_type_name(): void
public function can_return_correct_type_name(): void
{
$type = new class extends BaseType {
protected const TYPE_NAME = 'custom_type';
Expand All @@ -59,7 +59,7 @@ public function returns_correct_type_name(): void
}

#[Test]
public function gets_correct_sql_declaration(): void
public function can_get_correct_sql_declaration(): void
{
$type = new class extends BaseType {
protected const TYPE_NAME = 'custom_type';
Expand All @@ -76,7 +76,7 @@ public function gets_correct_sql_declaration(): void
}

#[Test]
public function requires_sql_comment_hint_returns_false(): void
public function can_return_false_for_sql_comment_hint_requirement(): void
{
$type = new class extends BaseType {
protected const TYPE_NAME = 'custom_type';
Expand Down
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 provideInvalidPHPValuesForDatabaseTransformation(): array
public static function provideInvalidDatabaseValueInputs(): array
{
return \array_merge(parent::provideInvalidPHPValuesForDatabaseTransformation(), [
return \array_merge(parent::provideInvalidDatabaseValueInputs(), [
['9223372036854775808'], // Greater than PHP_INT_MAX
['-9223372036854775809'], // Less than PHP_INT_MIN
['1.23e10'], // Scientific notation
Expand All @@ -33,7 +33,10 @@ public static function provideInvalidPHPValuesForDatabaseTransformation(): array
}

/**
* @return array<int, array{phpValue: int, postgresValue: string}>
* @return list<array{
* phpValue: int,
* postgresValue: string
* }>
*/
public static function provideValidTransformations(): array
{
Expand Down Expand Up @@ -76,7 +79,7 @@ public function throws_domain_exception_when_value_exceeds_range(string $outOfRa
}

/**
* @return array<array{string}>
* @return list<array{string}>
*/
public static function provideOutOfRangeValues(): array
{
Expand Down
21 changes: 14 additions & 7 deletions tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/CidrArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public function can_transform_to_php_value(?array $phpValue, ?string $postgresVa
}

/**
* @return array<string, array{phpValue: array|null, postgresValue: string|null}>
* @return array<string, array{
* phpValue: array|null,
* postgresValue: string|null
* }>
*/
public static function provideValidTransformations(): array
{
Expand Down Expand Up @@ -76,9 +79,9 @@ public static function provideValidTransformations(): array
];
}

#[DataProvider('provideInvalidPHPValuesForDatabaseTransformation')]
#[DataProvider('provideInvalidDatabaseValueInputs')]
#[Test]
public function throws_exception_when_invalid_data_provided_to_convert_to_database_value(mixed $phpValue): void
public function throws_exception_for_invalid_database_value_inputs(mixed $phpValue): void
{
$this->expectException(InvalidCidrArrayItemForPHPException::class);
$this->fixture->convertToDatabaseValue($phpValue, $this->platform); // @phpstan-ignore-line
Expand All @@ -87,7 +90,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_databa
/**
* @return array<string, array{mixed}>
*/
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
public static function provideInvalidDatabaseValueInputs(): array
{
return [
'invalid type' => ['not-an-array'],
Expand All @@ -100,12 +103,16 @@ public static function provideInvalidPHPValuesForDatabaseTransformation(): array
'empty string' => [['']], // Empty string in array
'whitespace only' => [[' ']], // Whitespace string in array
'malformed CIDR with spaces' => [['192.168.1.0 / 24']], // Space in CIDR notation
'valid value mixed with null array item' => [['192.168.1.0/24', null]],
'valid value mixed with integer array item' => [['192.168.1.0/24', 123]],
'valid value mixed with boolean array item' => [['192.168.1.0/24', true]],
'valid value mixed with object array item' => [['192.168.1.0/24', new \stdClass()]],
];
}

#[DataProvider('provideInvalidDatabaseValuesForPHPTransformationForPHPTransformation')]
#[DataProvider('provideInvalidPHPValueInputs')]
#[Test]
public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(string $postgresValue): void
public function throws_exception_for_invalid_php_value_inputs(string $postgresValue): void
{
$this->expectException(InvalidCidrArrayItemForPHPException::class);
$this->fixture->convertToPHPValue($postgresValue, $this->platform);
Expand All @@ -114,7 +121,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_php_va
/**
* @return array<string, array{string}>
*/
public static function provideInvalidDatabaseValuesForPHPTransformationForPHPTransformation(): array
public static function provideInvalidPHPValueInputs(): array
{
return [
'invalid format' => ['{"invalid-cidr"}'],
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/CidrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public static function provideValidTransformations(): array
];
}

#[DataProvider('provideInvalidPHPValuesForDatabaseTransformation')]
#[DataProvider('provideInvalidDatabaseValueInputs')]
#[Test]
public function throws_exception_when_invalid_data_provided_to_convert_to_database_value(mixed $phpValue): void
public function throws_exception_for_invalid_database_value_inputs(mixed $phpValue): void
{
$this->expectException(InvalidCidrForPHPException::class);
$this->fixture->convertToDatabaseValue($phpValue, $this->platform);
Expand All @@ -104,7 +104,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_databa
/**
* @return array<string, array{mixed}>
*/
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
public static function provideInvalidDatabaseValueInputs(): array
{
return [
'empty string' => [''],
Expand All @@ -124,9 +124,9 @@ public static function provideInvalidPHPValuesForDatabaseTransformation(): array
];
}

#[DataProvider('provideInvalidDatabaseValuesForPHPTransformation')]
#[DataProvider('provideInvalidPHPValueInputs')]
#[Test]
public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(mixed $dbValue): void
public function throws_exception_for_invalid_php_value_inputs(mixed $dbValue): void
{
$this->expectException(InvalidCidrForDatabaseException::class);
$this->fixture->convertToPHPValue($dbValue, $this->platform);
Expand All @@ -135,7 +135,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_php_va
/**
* @return array<string, array{mixed}>
*/
public static function provideInvalidDatabaseValuesForPHPTransformation(): array
public static function provideInvalidPHPValueInputs(): 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 provideInvalidPHPValuesForDatabaseTransformation(): array
public static function provideInvalidDatabaseValueInputs(): array
{
return \array_merge(parent::provideInvalidPHPValuesForDatabaseTransformation(), [
return \array_merge(parent::provideInvalidDatabaseValueInputs(), [
['1.7976931348623157E+309'], // Too large
['-1.7976931348623157E+309'], // Too small
['1.123456789012345678'], // Too many decimal places (>15)
Expand All @@ -35,7 +35,10 @@ public static function provideInvalidPHPValuesForDatabaseTransformation(): array
}

/**
* @return array<int, array{phpValue: float, postgresValue: string}>
* @return list<array{
* phpValue: float,
* postgresValue: string
* }>
*/
public static function provideValidTransformations(): array
{
Expand Down
17 changes: 10 additions & 7 deletions tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/InetArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public function can_transform_to_php_value(?array $phpValue, ?string $postgresVa
}

/**
* @return array<string, array{phpValue: array|null, postgresValue: string|null}>
* @return array<string, array{
* phpValue: array|null,
* postgresValue: string|null
* }>
*/
public static function provideValidTransformations(): array
{
Expand Down Expand Up @@ -96,9 +99,9 @@ public static function provideValidTransformations(): array
];
}

#[DataProvider('provideInvalidPHPValuesForDatabaseTransformation')]
#[DataProvider('provideInvalidDatabaseValueInputs')]
#[Test]
public function throws_exception_when_invalid_data_provided_to_convert_to_database_value(mixed $phpValue): void
public function throws_exception_for_invalid_database_value_inputs(mixed $phpValue): void
{
$this->expectException(InvalidInetArrayItemForPHPException::class);
$this->fixture->convertToDatabaseValue($phpValue, $this->platform); // @phpstan-ignore-line
Expand All @@ -107,7 +110,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_databa
/**
* @return array<string, array{mixed}>
*/
public static function provideInvalidPHPValuesForDatabaseTransformation(): array
public static function provideInvalidDatabaseValueInputs(): array
{
return [
'invalid type' => ['not-an-array'],
Expand All @@ -128,9 +131,9 @@ public static function provideInvalidPHPValuesForDatabaseTransformation(): array
];
}

#[DataProvider('provideInvalidDatabaseValuesForPHPTransformation')]
#[DataProvider('provideInvalidPHPValueInputs')]
#[Test]
public function throws_exception_when_invalid_data_provided_to_convert_to_php_value(string $postgresValue): void
public function throws_exception_for_invalid_php_value_inputs(string $postgresValue): void
{
$this->expectException(InvalidInetArrayItemForPHPException::class);

Expand All @@ -140,7 +143,7 @@ public function throws_exception_when_invalid_data_provided_to_convert_to_php_va
/**
* @return array<string, array{string}>
*/
public static function provideInvalidDatabaseValuesForPHPTransformation(): array
public static function provideInvalidPHPValueInputs(): array
{
return [
'invalid format' => ['{"invalid-ip"}'],
Expand Down
Loading
Loading