Skip to content

Commit 86e6eb6

Browse files
feat: add multiple arguments support for ARRAY
1 parent 91fd918 commit 86e6eb6

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

composer.json

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,33 @@
6060
},
6161

6262
"scripts": {
63+
"php-cs-fixer": [
64+
"PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --no-interaction --diff -v"
65+
],
66+
"phpunit": [
67+
"phpunit --configuration='./ci/phpunit/config.xml'"
68+
],
69+
"rector": [
70+
"rector --config='./ci/rector/config.php' --ansi --no-progress-bar"
71+
],
72+
6373
"check-code-style": [
64-
"php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --dry-run --no-interaction --diff -v",
65-
"rector --config='./ci/rector/config.php' --ansi --no-progress-bar --dry-run"
74+
"@php-cs-fixer --dry-run",
75+
"@rector --dry-run"
6676
],
6777
"fix-code-style": [
68-
"rector --config='./ci/rector/config.php' --ansi --no-progress-bar",
69-
"php-cs-fixer fix --config='./ci/php-cs-fixer/config.php' --show-progress=none --no-interaction --diff -v"
78+
"@rector",
79+
"@php-cs-fixer"
7080
],
7181
"run-static-analysis": [
7282
"phpstan analyse --configuration='./ci/phpstan/config.neon'",
7383
"deptrac analyze --config-file='./ci/deptrac/config.yml' --cache-file='./ci/deptrac/.cache' --no-interaction --no-progress"
7484
],
7585
"run-tests": [
76-
"phpunit --configuration='./ci/phpunit/config.xml'"
86+
"@phpunit"
7787
],
7888
"run-tests-with-clover": [
79-
"phpunit --configuration='./ci/phpunit/config.xml' --coverage-clover './build/logs/clover.xml'"
89+
"@phpunit --coverage-clover './build/logs/clover.xml'"
8090
]
8191
},
8292

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Arr.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
66

7+
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
8+
79
/**
810
* Implementation of PostgreSQL ARRAY[].
911
*
@@ -12,11 +14,20 @@
1214
*
1315
* @author Martin Georgiev <martin.georgiev@gmail.com>
1416
*/
15-
class Arr extends BaseFunction
17+
class Arr extends BaseVariadicFunction
1618
{
19+
protected string $commonNodeMapping = 'StringPrimary';
20+
1721
protected function customizeFunction(): void
1822
{
1923
$this->setFunctionPrototype('ARRAY[%s]');
20-
$this->addNodeMapping('StringPrimary');
24+
}
25+
26+
protected function validateArguments(array $arguments): void
27+
{
28+
$argumentCount = \count($arguments);
29+
if ($argumentCount === 0) {
30+
throw InvalidArgumentForVariadicFunctionException::atLeast('ARRAY', 1);
31+
}
2132
}
2233
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6+
7+
use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsArrays;
8+
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Arr;
9+
10+
class ArrTest extends TestCase
11+
{
12+
protected function getStringFunctions(): array
13+
{
14+
return [
15+
'ARRAY' => Arr::class,
16+
];
17+
}
18+
19+
protected function getExpectedSqlStatements(): array
20+
{
21+
return [
22+
// Multiple literal values
23+
"SELECT ARRAY['foo', 'bar', 'baz'] AS sclr_0 FROM ContainsArrays c0_",
24+
// Column references
25+
'SELECT ARRAY[c0_.array1] AS sclr_0 FROM ContainsArrays c0_',
26+
// Mix of column references and literals
27+
"SELECT ARRAY[c0_.array1, 'test-value', c0_.array2] AS sclr_0 FROM ContainsArrays c0_",
28+
];
29+
}
30+
31+
protected function getDqlStatements(): array
32+
{
33+
return [
34+
// Multiple literal values
35+
\sprintf("SELECT ARRAY('foo', 'bar', 'baz') FROM %s e", ContainsArrays::class),
36+
// Column references
37+
\sprintf('SELECT ARRAY(e.array1) FROM %s e', ContainsArrays::class),
38+
// Mix of column references and literals
39+
\sprintf("SELECT ARRAY(e.array1, 'test-value', e.array2) FROM %s e", ContainsArrays::class),
40+
];
41+
}
42+
}

0 commit comments

Comments
 (0)