Skip to content

Commit 4cde68c

Browse files
no message
1 parent 45e5358 commit 4cde68c

File tree

8 files changed

+37
-22
lines changed

8 files changed

+37
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
*
1515
* @author Martin Georgiev <martin.georgiev@gmail.com>
1616
*
17-
* @example Using it in DQL: "SELECT REGEXP_COUNT(e.text, '\d\d\d') FROM Entity e"
17+
* @example Using it in DQL: "SELECT REGEXP_COUNT(e.text, '\d\d\d', 1, 'i') FROM Entity e"
1818
*/
1919
class RegexpCount extends BaseVariadicFunction
2020
{
2121
protected function getNodeMappingPattern(): array
2222
{
2323
return [
2424
'StringPrimary,StringPrimary,ArithmeticPrimary,StringPrimary',
25+
'StringPrimary,StringPrimary,ArithmeticPrimary',
2526
'StringPrimary,StringPrimary',
2627
];
2728
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010
* Returns the position within string where the Nth match of the POSIX regular expression pattern occurs,
1111
* or zero if there is no such match.
1212
*
13-
* @see https://www.postgresql.org/docs/15/functions-matching.html#FUNCTIONS-POSIX-REGEXP
13+
* @see https://www.postgresql.org/docs/17/functions-matching.html#FUNCTIONS-POSIX-REGEXP
1414
* @since 3.1
1515
*
1616
* @author Martin Georgiev <martin.georgiev@gmail.com>
1717
*
18-
* @example Using it in DQL: "SELECT REGEXP_INSTR(e.text, 'c(.)(..)', 1, 1, 0, 'i') FROM Entity e"
18+
* @example Using it in DQL: "SELECT REGEXP_INSTR(e.text, 'c(.)(..)', 1, 1, 0, 'i', 2) FROM Entity e"
1919
*/
2020
class RegexpInstr extends BaseVariadicFunction
2121
{
2222
protected function getNodeMappingPattern(): array
2323
{
2424
return [
25+
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary,ArithmeticPrimary',
2526
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary',
2627
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,ArithmeticPrimary',
28+
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary',
29+
'StringPrimary,StringPrimary,ArithmeticPrimary',
2730
'StringPrimary,StringPrimary',
2831
];
2932
}
@@ -40,6 +43,6 @@ protected function getMinArgumentCount(): int
4043

4144
protected function getMaxArgumentCount(): int
4245
{
43-
return 6;
46+
return 7;
4447
}
4548
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@
77
/**
88
* Implementation of PostgreSQL REGEXP_REPLACE().
99
*
10-
* @see https://www.postgresql.org/docs/15/functions-matching.html#FUNCTIONS-POSIX-REGEXP
10+
* Replaces substring(s) matching a POSIX regular expression pattern with a replacement string.
11+
*
12+
* @see https://www.postgresql.org/docs/17/functions-matching.html#FUNCTIONS-POSIX-REGEXP
1113
* @since 2.5
1214
*
1315
* @author Colin Doig
16+
*
17+
* @example Using it in DQL: "SELECT REGEXP_REPLACE(e.text, 'pattern', 'replacement', 3, 2, 'i') FROM Entity e"
1418
*/
1519
class RegexpReplace extends BaseVariadicFunction
1620
{
1721
protected function getNodeMappingPattern(): array
1822
{
1923
return [
20-
'StringPrimary,StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary',
21-
'StringPrimary,StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary',
24+
'StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary',
25+
'StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary',
26+
'StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary,StringPrimary',
27+
'StringPrimary,StringPrimary,StringPrimary,ArithmeticPrimary',
2228
'StringPrimary,StringPrimary,StringPrimary,StringPrimary',
2329
'StringPrimary,StringPrimary,StringPrimary',
2430
];

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protected function getNodeMappingPattern(): array
2525
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary,ArithmeticPrimary',
2626
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary,StringPrimary',
2727
'StringPrimary,StringPrimary,ArithmeticPrimary,ArithmeticPrimary',
28+
'StringPrimary,StringPrimary,ArithmeticPrimary',
2829
'StringPrimary,StringPrimary',
2930
];
3031
}

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpCountTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ protected function getExpectedSqlStatements(): array
3030
'counts words' => "SELECT regexp_count(c0_.text1, '\\w+') AS sclr_0 FROM ContainsTexts c0_",
3131
'with start position' => "SELECT regexp_count(c0_.text1, '\\d\\d\\d', 1) AS sclr_0 FROM ContainsTexts c0_",
3232
'with flags' => "SELECT regexp_count(c0_.text1, '\\d\\d\\d', 1, 'i') AS sclr_0 FROM ContainsTexts c0_",
33-
'with all parameters' => "SELECT regexp_count(c0_.text1, '\\d\\d\\d', 1, 'i') AS sclr_0 FROM ContainsTexts c0_",
3433
];
3534
}
3635

@@ -41,7 +40,6 @@ protected function getDqlStatements(): array
4140
'counts words' => \sprintf("SELECT REGEXP_COUNT(e.text1, '\\w+') FROM %s e", ContainsTexts::class),
4241
'with start position' => \sprintf("SELECT REGEXP_COUNT(e.text1, '\\d\\d\\d', 1) FROM %s e", ContainsTexts::class),
4342
'with flags' => \sprintf("SELECT REGEXP_COUNT(e.text1, '\\d\\d\\d', 1, 'i') FROM %s e", ContainsTexts::class),
44-
'with all parameters' => \sprintf("SELECT REGEXP_COUNT(e.text1, '\\d\\d\\d', 1, 'i') FROM %s e", ContainsTexts::class),
4543
];
4644
}
4745

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpInstrTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ protected function getExpectedSqlStatements(): array
3131
'with start position' => "SELECT regexp_instr(c0_.text1, '\\d+', 1) AS sclr_0 FROM ContainsTexts c0_",
3232
'with start and occurrence' => "SELECT regexp_instr(c0_.text1, '\\d+', 1, 2) AS sclr_0 FROM ContainsTexts c0_",
3333
'with start, occurrence and return_option' => "SELECT regexp_instr(c0_.text1, '\\d+', 1, 2, 0) AS sclr_0 FROM ContainsTexts c0_",
34-
'with all parameters' => "SELECT regexp_instr(c0_.text1, '\\d+', 1, 2, 0, 'i') AS sclr_0 FROM ContainsTexts c0_",
34+
'with flags' => "SELECT regexp_instr(c0_.text1, '\\d+', 1, 2, 0, 'i') AS sclr_0 FROM ContainsTexts c0_",
35+
'with subexpr' => "SELECT regexp_instr(c0_.text1, '\\d+', 1, 2, 0, 'i', 2) AS sclr_0 FROM ContainsTexts c0_",
3536
];
3637
}
3738

@@ -43,7 +44,8 @@ protected function getDqlStatements(): array
4344
'with start position' => \sprintf("SELECT REGEXP_INSTR(e.text1, '\\d+', 1) FROM %s e", ContainsTexts::class),
4445
'with start and occurrence' => \sprintf("SELECT REGEXP_INSTR(e.text1, '\\d+', 1, 2) FROM %s e", ContainsTexts::class),
4546
'with start, occurrence and return_option' => \sprintf("SELECT REGEXP_INSTR(e.text1, '\\d+', 1, 2, 0) FROM %s e", ContainsTexts::class),
46-
'with all parameters' => \sprintf("SELECT REGEXP_INSTR(e.text1, '\\d+', 1, 2, 0, 'i') FROM %s e", ContainsTexts::class),
47+
'with flags' => \sprintf("SELECT REGEXP_INSTR(e.text1, '\\d+', 1, 2, 0, 'i') FROM %s e", ContainsTexts::class),
48+
'with subexpr' => \sprintf("SELECT REGEXP_INSTR(e.text1, '\\d+', 1, 2, 0, 'i', 2) FROM %s e", ContainsTexts::class),
4749
];
4850
}
4951

@@ -59,9 +61,9 @@ public function test_too_few_arguments_throws_exception(): void
5961
public function test_too_many_arguments_throws_exception(): void
6062
{
6163
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
62-
$this->expectExceptionMessage('regexp_instr() requires between 2 and 6 arguments');
64+
$this->expectExceptionMessage('regexp_instr() requires between 2 and 7 arguments');
6365

64-
$dql = \sprintf("SELECT REGEXP_INSTR(e.text1, 'c(.)(..)', 1, 1, 0, 'i', 'extra_arg') FROM %s e", ContainsTexts::class);
66+
$dql = \sprintf("SELECT REGEXP_INSTR(e.text1, 'c(.)(..)', 1, 1, 0, 'i', 2, 'extra_arg') FROM %s e", ContainsTexts::class);
6567
$this->buildEntityManager()->createQuery($dql)->getSQL();
6668
}
6769
}

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpReplaceTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@ protected function getExpectedSqlStatements(): array
2727
{
2828
return [
2929
'basic replacement' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement') AS sclr_0 FROM ContainsTexts c0_",
30-
'with flags' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement', 'i') AS sclr_0 FROM ContainsTexts c0_",
31-
'with start position' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement', 'i', 3) AS sclr_0 FROM ContainsTexts c0_",
32-
'with occurrence count' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement', 'i', 3, 2) AS sclr_0 FROM ContainsTexts c0_",
30+
'with flags but no start position' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement', 'i') AS sclr_0 FROM ContainsTexts c0_",
31+
'with start position' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement', 3) AS sclr_0 FROM ContainsTexts c0_",
32+
'with start position and flags' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement', 3, 'i') AS sclr_0 FROM ContainsTexts c0_",
33+
'with occurrence count but no flags' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement', 3, 2) AS sclr_0 FROM ContainsTexts c0_",
34+
'with occurrence count and flags' => "SELECT regexp_replace(c0_.text1, 'pattern', 'replacement', 3, 2, 'i') AS sclr_0 FROM ContainsTexts c0_",
3335
];
3436
}
3537

3638
protected function getDqlStatements(): array
3739
{
3840
return [
3941
'basic replacement' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement') FROM %s e", ContainsTexts::class),
40-
'with flags' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 'i') FROM %s e", ContainsTexts::class),
41-
'with start position' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 'i', 3) FROM %s e", ContainsTexts::class),
42-
'with occurrence count' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 'i', 3, 2) FROM %s e", ContainsTexts::class),
42+
'with flags but no start position' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 'i') FROM %s e", ContainsTexts::class),
43+
'with start position' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 3) FROM %s e", ContainsTexts::class),
44+
'with start position and flags' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 3, 'i') FROM %s e", ContainsTexts::class),
45+
'with occurrence count but no flags' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 3, 2) FROM %s e", ContainsTexts::class),
46+
'with occurrence count and flags' => \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 3, 2, 'i') FROM %s e", ContainsTexts::class),
4347
];
4448
}
4549

@@ -57,7 +61,7 @@ public function test_too_many_arguments_throws_exception(): void
5761
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
5862
$this->expectExceptionMessage('regexp_replace() requires between 3 and 6 arguments');
5963

60-
$dql = \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 'i', 3, 2, 'extra_arg') FROM %s e", ContainsTexts::class);
64+
$dql = \sprintf("SELECT REGEXP_REPLACE(e.text1, 'pattern', 'replacement', 3, 2, 'i', 'extra_arg') FROM %s e", ContainsTexts::class);
6165
$this->buildEntityManager()->createQuery($dql)->getSQL();
6266
}
6367
}

tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpSubstrTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function getExpectedSqlStatements(): array
3030
'extracts digits' => "SELECT regexp_substr(c0_.text1, '\\d+') AS sclr_0 FROM ContainsTexts c0_",
3131
'extracts digits with start and N parameters' => "SELECT regexp_substr(c0_.text1, '\\d+', 1, 4) AS sclr_0 FROM ContainsTexts c0_",
3232
'extracts digits with start and N parameters and flags' => "SELECT regexp_substr(c0_.text1, '\\d+', 1, 4, 'i') AS sclr_0 FROM ContainsTexts c0_",
33-
'extracts digits with start, N and subexpr parameters and flags' => "SELECT regexp_substr(c0_.text1, '\\d+', 1, 4, 'i', 3) AS sclr_0 FROM ContainsTexts c0_",
33+
'extracts digits with start, N parameters, flags and subexpr parameter' => "SELECT regexp_substr(c0_.text1, '\\d+', 1, 4, 'i', 3) AS sclr_0 FROM ContainsTexts c0_",
3434
];
3535
}
3636

@@ -41,7 +41,7 @@ protected function getDqlStatements(): array
4141
'extracts digits' => \sprintf("SELECT REGEXP_SUBSTR(e.text1, '\\d+') FROM %s e", ContainsTexts::class),
4242
'extracts digits with start and N parameters' => \sprintf("SELECT REGEXP_SUBSTR(e.text1, '\\d+', 1, 4) FROM %s e", ContainsTexts::class),
4343
'extracts digits with start and N parameters and flags' => \sprintf("SELECT REGEXP_SUBSTR(e.text1, '\\d+', 1, 4, 'i') FROM %s e", ContainsTexts::class),
44-
'extracts digits with start, N and subexpr parameters and flags' => \sprintf("SELECT REGEXP_SUBSTR(e.text1, '\\d+', 1, 4, 'i', 3) FROM %s e", ContainsTexts::class),
44+
'extracts digits with start, N parameters, flags and subexpr parameter' => \sprintf("SELECT REGEXP_SUBSTR(e.text1, '\\d+', 1, 4, 'i', 3) FROM %s e", ContainsTexts::class),
4545
];
4646
}
4747

0 commit comments

Comments
 (0)