Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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 @@ -19,14 +19,14 @@ protected function getStringFunctions(): array
protected function getExpectedSqlStatements(): array
{
return [
'SELECT c0_.id AS id_0 FROM ContainsArrays c0_ WHERE c0_.id > ALL(c0_.textArray)',
'all elements match condition' => 'SELECT c0_.id AS id_0 FROM ContainsArrays c0_ WHERE c0_.id > ALL(c0_.textArray)',
];
}

protected function getDqlStatements(): array
{
return [
\sprintf('SELECT e.id FROM %s e WHERE e.id > ALL_OF(e.textArray)', ContainsArrays::class),
'all elements match condition' => \sprintf('SELECT e.id FROM %s e WHERE e.id > ALL_OF(e.textArray)', ContainsArrays::class),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ArrayPosition;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseVariadicFunction;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

class ArrayPositionTest extends BaseVariadicFunctionTestCase
Expand Down Expand Up @@ -44,23 +45,30 @@ protected function getDqlStatements(): array
];
}

#[DataProvider('provideInvalidArgumentCountCases')]
#[Test]
public function too_few_arguments_throws_exception(): void
public function throws_exception_for_invalid_argument_count(string $dql, string $expectedMessage): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('array_position() requires at least 2 arguments');
$this->expectExceptionMessage($expectedMessage);

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

#[Test]
public function too_many_arguments_throws_exception(): void
/**
* @return array<string, array{string, string}>
*/
public static function provideInvalidArgumentCountCases(): array
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('array_position() requires between 2 and 3 arguments');

$dql = \sprintf("SELECT ARRAY_POSITION(e.textArray, 0, 1, 'extra_arg') FROM %s e", ContainsArrays::class);
$this->buildEntityManager()->createQuery($dql)->getSQL();
return [
'too few arguments' => [
\sprintf('SELECT ARRAY_POSITION(e.textArray) FROM %s e', ContainsArrays::class),
'array_position() requires at least 2 arguments',
],
'too many arguments' => [
\sprintf("SELECT ARRAY_POSITION(e.textArray, 0, 1, 'extra_arg') FROM %s e", ContainsArrays::class),
'array_position() requires between 2 and 3 arguments',
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function getDqlStatements(): array
}

#[Test]
public function invalid_boolean_throws_exception(): void
public function throws_exception_for_invalid_boolean_value(): void
{
$this->expectException(InvalidBooleanException::class);
$this->expectExceptionMessage('Invalid boolean value "invalid" provided for array_to_json. Must be "true" or "false".');
Expand All @@ -52,7 +52,7 @@ public function invalid_boolean_throws_exception(): void
}

#[Test]
public function too_many_arguments_throws_exception(): void
public function throws_exception_for_too_many_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('array_to_json() requires between 1 and 2 arguments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ protected function getStringFunctions(): array
protected function getExpectedSqlStatements(): array
{
return [
'SELECT CEIL(c0_.decimal1) AS sclr_0 FROM ContainsDecimals c0_',
'rounds decimal up to nearest integer' => 'SELECT CEIL(c0_.decimal1) AS sclr_0 FROM ContainsDecimals c0_',
];
}

protected function getDqlStatements(): array
{
return [
\sprintf('SELECT CEIL(e.decimal1) FROM %s e', ContainsDecimals::class),
'rounds decimal up to nearest integer' => \sprintf('SELECT CEIL(e.decimal1) FROM %s e', ContainsDecimals::class),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getDqlStatements(): array
}

#[Test]
public function invalid_timezone_throws_exception(): void
public function throws_exception_for_invalid_timezone(): void
{
$this->expectException(InvalidTimezoneException::class);
$this->expectExceptionMessage('Invalid timezone "Invalid/Timezone" provided for date_add');
Expand All @@ -56,7 +56,7 @@ public function invalid_timezone_throws_exception(): void
}

#[Test]
public function too_few_arguments_throws_exception(): void
public function throws_exception_for_too_few_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('date_add() requires at least 2 arguments');
Expand All @@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
}

#[Test]
public function too_many_arguments_throws_exception(): void
public function throws_exception_for_too_many_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('date_add() requires between 2 and 3 arguments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\DateSubtract;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidTimezoneException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

class DateSubtractTest extends BaseVariadicFunctionTestCase
Expand Down Expand Up @@ -44,7 +45,7 @@ protected function getDqlStatements(): array
}

#[Test]
public function invalid_timezone_throws_exception(): void
public function throws_exception_for_invalid_timezone(): void
{
$this->expectException(InvalidTimezoneException::class);
$this->expectExceptionMessage('Invalid timezone "Invalid/Timezone" provided for date_subtract');
Expand All @@ -53,23 +54,30 @@ public function invalid_timezone_throws_exception(): void
$this->buildEntityManager()->createQuery($dql)->getSQL();
}

#[DataProvider('provideInvalidArgumentCountCases')]
#[Test]
public function too_few_arguments_throws_exception(): void
public function throws_exception_for_invalid_argument_count(string $dql, string $expectedMessage): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('date_subtract() requires at least 2 arguments');
$this->expectExceptionMessage($expectedMessage);

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

#[Test]
public function too_many_arguments_throws_exception(): void
/**
* @return array<string, array{string, string}>
*/
public static function provideInvalidArgumentCountCases(): array
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('date_subtract() requires between 2 and 3 arguments');

$dql = \sprintf("SELECT DATE_SUBTRACT(e.datetimetz1, '1 day', 'Europe/Sofia', 'extra_arg') FROM %s e", ContainsDates::class);
$this->buildEntityManager()->createQuery($dql)->getSQL();
return [
'too few arguments' => [
\sprintf('SELECT DATE_SUBTRACT(e.datetimetz1) FROM %s e', ContainsDates::class),
'date_subtract() requires at least 2 arguments',
],
'too many arguments' => [
\sprintf("SELECT DATE_SUBTRACT(e.datetimetz1, '1 day', 'Europe/Sofia', 'extra_arg') FROM %s e", ContainsDates::class),
'date_subtract() requires between 2 and 3 arguments',
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ protected function getStringFunctions(): array
protected function getExpectedSqlStatements(): array
{
return [
'SELECT FLOOR(c0_.decimal1) AS sclr_0 FROM ContainsDecimals c0_',
'rounds decimal down to nearest integer' => 'SELECT FLOOR(c0_.decimal1) AS sclr_0 FROM ContainsDecimals c0_',
];
}

protected function getDqlStatements(): array
{
return [
\sprintf('SELECT FLOOR(e.decimal1) FROM %s e', ContainsDecimals::class),
'rounds decimal down to nearest integer' => \sprintf('SELECT FLOOR(e.decimal1) FROM %s e', ContainsDecimals::class),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getDqlStatements(): array
}

#[Test]
public function throws_exception_when_single_argument_given(): void
public function throws_exception_for_insufficient_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ protected function getStringFunctions(): array
protected function getExpectedSqlStatements(): array
{
return [
"SELECT c0_.text1 ilike 'TEST' AS sclr_0 FROM ContainsTexts c0_",
'case-insensitive pattern matching' => "SELECT c0_.text1 ilike 'TEST' AS sclr_0 FROM ContainsTexts c0_",
];
}

protected function getDqlStatements(): array
{
return [
\sprintf("SELECT ILIKE(e.text1,'TEST') FROM %s e", ContainsTexts::class),
'case-insensitive pattern matching' => \sprintf("SELECT ILIKE(e.text1,'TEST') FROM %s e", ContainsTexts::class),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getDqlStatements(): array
}

#[Test]
public function throws_exception_when_odd_number_of_arguments_given(): void
public function throws_exception_for_odd_number_of_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getDqlStatements(): array
}

#[Test]
public function throws_exception_when_odd_number_of_arguments_given(): void
public function throws_exception_for_odd_number_of_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function getDqlStatements(): array
}

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

#[Test]
public function too_few_arguments_throws_exception(): void
public function throws_exception_for_too_few_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_insert() requires at least 3 arguments');
Expand All @@ -56,7 +56,7 @@ public function too_few_arguments_throws_exception(): void
}

#[Test]
public function too_many_arguments_throws_exception(): void
public function throws_exception_for_too_many_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_insert() requires between 3 and 4 arguments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getDqlStatements(): array
}

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

#[Test]
public function too_few_arguments_throws_exception(): void
public function throws_exception_for_too_few_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_path_exists() requires at least 2 arguments');
Expand All @@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
}

#[Test]
public function too_many_arguments_throws_exception(): void
public function throws_exception_for_too_many_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_path_exists() requires between 2 and 4 arguments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getDqlStatements(): array
}

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

#[Test]
public function too_few_arguments_throws_exception(): void
public function throws_exception_for_too_few_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_path_match() requires at least 2 arguments');
Expand All @@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
}

#[Test]
public function too_many_arguments_throws_exception(): void
public function throws_exception_for_too_many_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_path_match() requires between 2 and 4 arguments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getDqlStatements(): array
}

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

#[Test]
public function too_few_arguments_throws_exception(): void
public function throws_exception_for_too_few_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_path_query_array() requires at least 2 arguments');
Expand All @@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
}

#[Test]
public function too_many_arguments_throws_exception(): void
public function throws_exception_for_too_many_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_path_query_array() requires between 2 and 4 arguments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function getDqlStatements(): array
}

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

#[Test]
public function too_few_arguments_throws_exception(): void
public function throws_exception_for_too_few_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_path_query_first() requires at least 2 arguments');
Expand All @@ -66,7 +66,7 @@ public function too_few_arguments_throws_exception(): void
}

#[Test]
public function too_many_arguments_throws_exception(): void
public function throws_exception_for_too_many_arguments(): void
{
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$this->expectExceptionMessage('jsonb_path_query_first() requires between 2 and 4 arguments');
Expand Down
Loading
Loading