Skip to content

Commit ba7081b

Browse files
no message
1 parent 6e368e9 commit ba7081b

27 files changed

+147
-99
lines changed

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/ArrayPositionTest.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayPosition;
99
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseVariadicFunction;
1010
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\Attributes\Test;
1213

1314
class ArrayPositionTest extends BaseVariadicFunctionTestCase
@@ -44,23 +45,30 @@ protected function getDqlStatements(): array
4445
];
4546
}
4647

48+
#[DataProvider('provideInvalidArgumentCountCases')]
4749
#[Test]
48-
public function too_few_arguments_throws_exception(): void
50+
public function throws_exception_for_invalid_argument_count(string $dql, string $expectedMessage): void
4951
{
5052
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
51-
$this->expectExceptionMessage('array_position() requires at least 2 arguments');
53+
$this->expectExceptionMessage($expectedMessage);
5254

53-
$dql = \sprintf('SELECT ARRAY_POSITION(e.textArray) FROM %s e', ContainsArrays::class);
5455
$this->buildEntityManager()->createQuery($dql)->getSQL();
5556
}
5657

57-
#[Test]
58-
public function too_many_arguments_throws_exception(): void
58+
/**
59+
* @return array<string, array{string, string}>
60+
*/
61+
public static function provideInvalidArgumentCountCases(): array
5962
{
60-
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
61-
$this->expectExceptionMessage('array_position() requires between 2 and 3 arguments');
62-
63-
$dql = \sprintf("SELECT ARRAY_POSITION(e.textArray, 0, 1, 'extra_arg') FROM %s e", ContainsArrays::class);
64-
$this->buildEntityManager()->createQuery($dql)->getSQL();
63+
return [
64+
'too few arguments' => [
65+
\sprintf('SELECT ARRAY_POSITION(e.textArray) FROM %s e', ContainsArrays::class),
66+
'array_position() requires at least 2 arguments',
67+
],
68+
'too many arguments' => [
69+
\sprintf("SELECT ARRAY_POSITION(e.textArray, 0, 1, 'extra_arg') FROM %s e", ContainsArrays::class),
70+
'array_position() requires between 2 and 3 arguments',
71+
],
72+
];
6573
}
6674
}

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DateSubtractTest.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\DateSubtract;
1010
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
1111
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidTimezoneException;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1213
use PHPUnit\Framework\Attributes\Test;
1314

1415
class DateSubtractTest extends BaseVariadicFunctionTestCase
@@ -44,7 +45,7 @@ protected function getDqlStatements(): array
4445
}
4546

4647
#[Test]
47-
public function invalid_timezone_throws_exception(): void
48+
public function throws_exception_for_invalid_timezone(): void
4849
{
4950
$this->expectException(InvalidTimezoneException::class);
5051
$this->expectExceptionMessage('Invalid timezone "Invalid/Timezone" provided for date_subtract');
@@ -53,23 +54,30 @@ public function invalid_timezone_throws_exception(): void
5354
$this->buildEntityManager()->createQuery($dql)->getSQL();
5455
}
5556

57+
#[DataProvider('provideInvalidArgumentCountCases')]
5658
#[Test]
57-
public function too_few_arguments_throws_exception(): void
59+
public function throws_exception_for_invalid_argument_count(string $dql, string $expectedMessage): void
5860
{
5961
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
60-
$this->expectExceptionMessage('date_subtract() requires at least 2 arguments');
62+
$this->expectExceptionMessage($expectedMessage);
6163

62-
$dql = \sprintf('SELECT DATE_SUBTRACT(e.datetimetz1) FROM %s e', ContainsDates::class);
6364
$this->buildEntityManager()->createQuery($dql)->getSQL();
6465
}
6566

66-
#[Test]
67-
public function too_many_arguments_throws_exception(): void
67+
/**
68+
* @return array<string, array{string, string}>
69+
*/
70+
public static function provideInvalidArgumentCountCases(): array
6871
{
69-
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
70-
$this->expectExceptionMessage('date_subtract() requires between 2 and 3 arguments');
71-
72-
$dql = \sprintf("SELECT DATE_SUBTRACT(e.datetimetz1, '1 day', 'Europe/Sofia', 'extra_arg') FROM %s e", ContainsDates::class);
73-
$this->buildEntityManager()->createQuery($dql)->getSQL();
72+
return [
73+
'too few arguments' => [
74+
\sprintf('SELECT DATE_SUBTRACT(e.datetimetz1) FROM %s e', ContainsDates::class),
75+
'date_subtract() requires at least 2 arguments',
76+
],
77+
'too many arguments' => [
78+
\sprintf("SELECT DATE_SUBTRACT(e.datetimetz1, '1 day', 'Europe/Sofia', 'extra_arg') FROM %s e", ContainsDates::class),
79+
'date_subtract() requires between 2 and 3 arguments',
80+
],
81+
];
7482
}
7583
}

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/GreatestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function getDqlStatements(): array
4343
}
4444

4545
#[Test]
46-
public function throws_exception_when_single_argument_given(): void
46+
public function throws_exception_for_insufficient_arguments(): void
4747
{
4848
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
4949

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonBuildObjectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function getDqlStatements(): array
4343
}
4444

4545
#[Test]
46-
public function throws_exception_when_odd_number_of_arguments_given(): void
46+
public function throws_exception_for_invalid_argument_count(): void
4747
{
4848
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
4949

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbBuildObjectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function getDqlStatements(): array
4343
}
4444

4545
#[Test]
46-
public function throws_exception_when_odd_number_of_arguments_given(): void
46+
public function throws_exception_for_invalid_argument_count(): void
4747
{
4848
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
4949

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbInsertTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function getDqlStatements(): array
3636
}
3737

3838
#[Test]
39-
public function invalid_boolean_throws_exception(): void
39+
public function throws_exception_for_invalid_boolean(): void
4040
{
4141
$this->expectException(InvalidBooleanException::class);
4242
$this->expectExceptionMessage('Invalid boolean value "invalid" provided for jsonb_insert. Must be "true" or "false".');
@@ -46,7 +46,7 @@ public function invalid_boolean_throws_exception(): void
4646
}
4747

4848
#[Test]
49-
public function too_few_arguments_throws_exception(): void
49+
public function throws_exception_for_too_few_arguments(): void
5050
{
5151
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
5252
$this->expectExceptionMessage('jsonb_insert() requires at least 3 arguments');
@@ -56,7 +56,7 @@ public function too_few_arguments_throws_exception(): void
5656
}
5757

5858
#[Test]
59-
public function too_many_arguments_throws_exception(): void
59+
public function throws_exception_for_too_many_arguments(): void
6060
{
6161
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
6262
$this->expectExceptionMessage('jsonb_insert() requires between 3 and 4 arguments');

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathExistsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function getDqlStatements(): array
4646
}
4747

4848
#[Test]
49-
public function invalid_boolean_throws_exception(): void
49+
public function throws_exception_for_invalid_boolean(): void
5050
{
5151
$this->expectException(InvalidBooleanException::class);
5252
$this->expectExceptionMessage('Invalid boolean value "invalid" provided for jsonb_path_exists. Must be "true" or "false".');
@@ -56,7 +56,7 @@ public function invalid_boolean_throws_exception(): void
5656
}
5757

5858
#[Test]
59-
public function too_few_arguments_throws_exception(): void
59+
public function throws_exception_for_too_few_arguments(): void
6060
{
6161
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
6262
$this->expectExceptionMessage('jsonb_path_exists() requires at least 2 arguments');
@@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
6666
}
6767

6868
#[Test]
69-
public function too_many_arguments_throws_exception(): void
69+
public function throws_exception_for_too_many_arguments(): void
7070
{
7171
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
7272
$this->expectExceptionMessage('jsonb_path_exists() requires between 2 and 4 arguments');

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathMatchTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function getDqlStatements(): array
4646
}
4747

4848
#[Test]
49-
public function invalid_boolean_throws_exception(): void
49+
public function throws_exception_for_invalid_boolean(): void
5050
{
5151
$this->expectException(InvalidBooleanException::class);
5252
$this->expectExceptionMessage('Invalid boolean value "invalid" provided for jsonb_path_match. Must be "true" or "false".');
@@ -56,7 +56,7 @@ public function invalid_boolean_throws_exception(): void
5656
}
5757

5858
#[Test]
59-
public function too_few_arguments_throws_exception(): void
59+
public function throws_exception_for_too_few_arguments(): void
6060
{
6161
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
6262
$this->expectExceptionMessage('jsonb_path_match() requires at least 2 arguments');
@@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
6666
}
6767

6868
#[Test]
69-
public function too_many_arguments_throws_exception(): void
69+
public function throws_exception_for_too_many_arguments(): void
7070
{
7171
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
7272
$this->expectExceptionMessage('jsonb_path_match() requires between 2 and 4 arguments');

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathQueryArrayTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function getDqlStatements(): array
4646
}
4747

4848
#[Test]
49-
public function invalid_boolean_throws_exception(): void
49+
public function throws_exception_for_invalid_boolean(): void
5050
{
5151
$this->expectException(InvalidBooleanException::class);
5252
$this->expectExceptionMessage('Invalid boolean value "invalid" provided for jsonb_path_query_array. Must be "true" or "false".');
@@ -56,7 +56,7 @@ public function invalid_boolean_throws_exception(): void
5656
}
5757

5858
#[Test]
59-
public function too_few_arguments_throws_exception(): void
59+
public function throws_exception_for_too_few_arguments(): void
6060
{
6161
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
6262
$this->expectExceptionMessage('jsonb_path_query_array() requires at least 2 arguments');
@@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
6666
}
6767

6868
#[Test]
69-
public function too_many_arguments_throws_exception(): void
69+
public function throws_exception_for_too_many_arguments(): void
7070
{
7171
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
7272
$this->expectExceptionMessage('jsonb_path_query_array() requires between 2 and 4 arguments');

tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/JsonbPathQueryFirstTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function getDqlStatements(): array
4646
}
4747

4848
#[Test]
49-
public function invalid_boolean_throws_exception(): void
49+
public function throws_exception_for_invalid_boolean(): void
5050
{
5151
$this->expectException(InvalidBooleanException::class);
5252
$this->expectExceptionMessage('Invalid boolean value "invalid" provided for jsonb_path_query_first. Must be "true" or "false".');
@@ -56,7 +56,7 @@ public function invalid_boolean_throws_exception(): void
5656
}
5757

5858
#[Test]
59-
public function too_few_arguments_throws_exception(): void
59+
public function throws_exception_for_too_few_arguments(): void
6060
{
6161
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
6262
$this->expectExceptionMessage('jsonb_path_query_first() requires at least 2 arguments');
@@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
6666
}
6767

6868
#[Test]
69-
public function too_many_arguments_throws_exception(): void
69+
public function throws_exception_for_too_many_arguments(): void
7070
{
7171
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
7272
$this->expectExceptionMessage('jsonb_path_query_first() requires between 2 and 4 arguments');

0 commit comments

Comments
 (0)