-
-
Notifications
You must be signed in to change notification settings - Fork 56
feat: add support for specifying explicit range bounds #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
874d686
chore: test functions against a real PostgreSQL server
martin-georgiev 0924b26
no message
martin-georgiev ec954a5
no message
martin-georgiev 8b2bdee
no message
martin-georgiev 255144d
feat: add support for specifying explicit range bounds
martin-georgiev ff1a416
Merge branch 'main' into integrations3
martin-georgiev 305cd32
add integration tests
martin-georgiev f248854
Merge branch 'integrations3' of https://github.com/martin-georgiev/po…
martin-georgiev 7678c61
no message
martin-georgiev ba33795
no message
martin-georgiev 7e1316c
no message
martin-georgiev 57b2413
no message
martin-georgiev 80dc963
no message
martin-georgiev fe42c5b
no message
martin-georgiev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/DaterangeTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Integration\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Daterange; | ||
|
|
||
| class DaterangeTest extends DateTestCase | ||
| { | ||
| protected function getStringFunctions(): array | ||
| { | ||
| return [ | ||
| 'DATERANGE' => Daterange::class, | ||
| ]; | ||
| } | ||
|
|
||
| public function test_daterange(): void | ||
| { | ||
| $dql = 'SELECT DATERANGE(t.date1, t.date2) as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsDates t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('[2023-06-15,2023-06-16)', $result[0]['result']); | ||
| } | ||
|
|
||
| public function test_daterange_with_bounds(): void | ||
| { | ||
| $dql = 'SELECT DATERANGE(t.date1, t.date2, "[)") as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsDates t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('[2023-06-15,2023-06-16)', $result[0]['result']); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Int4rangeTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Integration\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Int4range; | ||
|
|
||
| class Int4rangeTest extends JsonTestCase | ||
| { | ||
| protected function getStringFunctions(): array | ||
| { | ||
| return [ | ||
| 'INT4RANGE' => Int4range::class, | ||
| ]; | ||
| } | ||
|
|
||
| public function test_int4range(): void | ||
| { | ||
| $dql = 'SELECT INT4RANGE(:start, :end) as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql, [ | ||
| 'start' => 10, | ||
| 'end' => 20, | ||
| ]); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('[10,20)', $result[0]['result']); | ||
| } | ||
|
|
||
| public function test_int4range_with_bounds(): void | ||
| { | ||
| $dql = 'SELECT INT4RANGE(:start, :end, "[)") as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql, [ | ||
| 'start' => 10, | ||
| 'end' => 20, | ||
| ]); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('[10,20)', $result[0]['result']); | ||
| } | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Int8rangeTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Integration\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Int8range; | ||
|
|
||
| class Int8rangeTest extends JsonTestCase | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| protected function getStringFunctions(): array | ||
| { | ||
| return [ | ||
| 'INT8RANGE' => Int8range::class, | ||
| ]; | ||
| } | ||
|
|
||
| public function test_int8range(): void | ||
| { | ||
| $dql = 'SELECT INT8RANGE(:start, :end) as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql, [ | ||
| 'start' => 100, | ||
| 'end' => 200, | ||
| ]); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('[100,200)', $result[0]['result']); | ||
| } | ||
|
|
||
| public function test_int8range_with_bounds(): void | ||
| { | ||
| $dql = 'SELECT INT8RANGE(:start, :end, "[)") as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql, [ | ||
| 'start' => 1000, | ||
| 'end' => 2000, | ||
| ]); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('[1000,2000)', $result[0]['result']); | ||
| } | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TsrangeTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Integration\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Tsrange; | ||
|
|
||
| class TsrangeTest extends DateTestCase | ||
| { | ||
| protected function getStringFunctions(): array | ||
| { | ||
| return [ | ||
| 'TSRANGE' => Tsrange::class, | ||
| ]; | ||
| } | ||
|
|
||
| public function test_tsrange(): void | ||
| { | ||
| $dql = 'SELECT TSRANGE(t.datetime1, t.datetime2) as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsDates t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('["2023-06-15 10:30:00","2023-06-16 11:45:00")', $result[0]['result']); | ||
| } | ||
|
|
||
| public function test_tsrange_with_bounds(): void | ||
| { | ||
| $dql = 'SELECT TSRANGE(t.datetime1, t.datetime2, "[)") as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsDates t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('["2023-06-15 10:30:00","2023-06-16 11:45:00")', $result[0]['result']); | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TstzrangeTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Tests\Integration\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions; | ||
|
|
||
| use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Tstzrange; | ||
|
|
||
| class TstzrangeTest extends JsonTestCase | ||
| { | ||
| protected function getStringFunctions(): array | ||
| { | ||
| return [ | ||
| 'TSTZRANGE' => Tstzrange::class, | ||
| ]; | ||
| } | ||
|
|
||
| public function test_tstzrange(): void | ||
| { | ||
| $dql = 'SELECT TSTZRANGE(\'2024-01-01 00:00:00+00\', \'2024-12-31 23:59:59+00\') as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons t WHERE t.id = 1'; | ||
| $result = $this->executeDqlQuery($dql); | ||
| $this->assertIsArray($result); | ||
| $this->assertNotEmpty($result[0]['result']); | ||
| $this->assertIsString($result[0]['result']); | ||
| $this->assertSame('["2024-01-01 00:00:00+00","2024-12-31 23:59:59+00")', $result[0]['result']); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Test for explicit bounds doesn't effectively verify the bounds parameter.
Both test methods use the same expected result ('[10,20)'), even though the second test explicitly specifies "[)" bounds. Since "[)" is the default bounds format anyway (as shown in the first test), this doesn't effectively verify that specifying explicit bounds works as expected.
Add a test case that uses different explicit bounds (e.g., '[]' for inclusive-inclusive) and verify that the result changes accordingly:
public function test_int4range_with_bounds(): void { - $dql = 'SELECT INT4RANGE(:start, :end, "[)") as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons t WHERE t.id = 1'; + $dql = 'SELECT INT4RANGE(:start, :end, "[]") as result FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsJsons t WHERE t.id = 1'; $result = $this->executeDqlQuery($dql, [ 'start' => 10, 'end' => 20, ]); $this->assertIsArray($result); $this->assertNotEmpty($result[0]['result']); $this->assertIsString($result[0]['result']); - $this->assertSame('[10,20)', $result[0]['result']); + $this->assertSame('[10,20]', $result[0]['result']); }🤖 Prompt for AI Agents