-
Couldn't load subscription status.
- Fork 1
Fixed passing DateTime instances into DoctrineDatabase::findBy() methods
#22
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
Open
Steveb-p
wants to merge
8
commits into
4.6
Choose a base branch
from
fix-date-time-find-by
base: 4.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
553bd45
Fixed passing DateTime instances into `DoctrineDatabase::findBy()` me…
Steveb-p 2c48633
Added basic test
Steveb-p cf73857
Fixed deprecation report
Steveb-p 9ba1f49
Added Comparison usage test
Steveb-p 24a9bba
Added Comparison usage test
Steveb-p fb34d83
Applied code review
Steveb-p 866b29a
Merge branch '4.6' into fix-date-time-find-by
Steveb-p e7ad6b4
Merge branch '4.6' into fix-date-time-find-by
Steveb-p 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
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,12 @@ | ||
| [ | ||
| { | ||
| "location": "Doctrine\\DBAL\\Platforms\\PostgreSqlPlatform", | ||
| "message": "Using ${var} in strings is deprecated, use {$var} instead", | ||
| "count": 1 | ||
| }, | ||
| { | ||
| "location": "Ibexa\\Tests\\CorePersistence\\Gateway\\AbstractDoctrineDatabaseTest::testDateTimeQueries", | ||
| "message": "The Doctrine\\DBAL\\Driver\\ResultStatement::fetch method is deprecated (Use fetchNumeric(), fetchAssociative() or fetchOne() instead.).", | ||
| "count": 1 | ||
| } | ||
| ] | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
| * @license For full copyright and license information view LICENSE file distributed with this source code. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ibexa\Tests\CorePersistence\Gateway; | ||
|
|
||
| use DateTimeImmutable; | ||
| use Doctrine\Common\Collections\Expr\Comparison; | ||
| use Doctrine\DBAL\Connection; | ||
| use Doctrine\DBAL\Driver\ResultStatement; | ||
| use Doctrine\DBAL\Platforms\PostgreSQL94Platform; | ||
| use Doctrine\DBAL\Query\Expression\ExpressionBuilder; | ||
| use Doctrine\DBAL\Query\QueryBuilder; | ||
| use Doctrine\DBAL\Types\Types; | ||
| use Ibexa\Contracts\CorePersistence\Gateway\AbstractDoctrineDatabase; | ||
| use Ibexa\Contracts\CorePersistence\Gateway\DoctrineSchemaMetadata; | ||
| use Ibexa\Contracts\CorePersistence\Gateway\DoctrineSchemaMetadataInterface; | ||
| use Ibexa\Contracts\CorePersistence\Gateway\DoctrineSchemaMetadataRegistryInterface; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** | ||
| * @covers \Ibexa\Contracts\CorePersistence\Gateway\AbstractDoctrineDatabase | ||
| */ | ||
| final class AbstractDoctrineDatabaseTest extends TestCase | ||
| { | ||
| /** | ||
| * @dataProvider provideForDateTimeQueries | ||
Steveb-p marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @param array<mixed|\Doctrine\Common\Collections\Expr\Comparison> $query | ||
| * @param array<array-key, string> $expectedParameters | ||
| */ | ||
| public function testDateTimeQueries( | ||
| array $query, | ||
| string $sql, | ||
| array $expectedParameters | ||
| ): void { | ||
| $connection = $this->createConnectionMock(); | ||
| $database = $this->createDatabaseGateway($connection); | ||
|
|
||
| $result = $this->createMock(ResultStatement::class); | ||
| $result->expects(self::once()) | ||
| ->method('fetch') | ||
| ->willReturn(false); | ||
|
|
||
| $connection->expects(self::once()) | ||
| ->method('executeQuery') | ||
| ->with( | ||
| self::identicalTo($sql), | ||
| self::identicalTo($expectedParameters), | ||
| ) | ||
| ->willReturn($result); | ||
|
|
||
| $database->findBy($query); | ||
| } | ||
|
|
||
| /** | ||
| * @return iterable<array{ | ||
| * array<mixed|\Doctrine\Common\Collections\Expr\Comparison>, | ||
| * non-empty-string, | ||
| * array<array-key, string>, | ||
| * }> | ||
| */ | ||
| public static function provideForDateTimeQueries(): iterable | ||
| { | ||
| yield [ | ||
| [ | ||
| new Comparison( | ||
| 'date_time_immutable_column', | ||
| Comparison::LT, | ||
| new DateTimeImmutable('2024-01-01 00:00:00'), | ||
| ), | ||
| ], | ||
| str_replace( | ||
| "\n", | ||
| ' ', | ||
| <<<SQL | ||
| SELECT __foo_table__.id, __foo_table__.date_time_immutable_column | ||
| FROM __foo_table__ __foo_table__ | ||
| WHERE __foo_table__.date_time_immutable_column < :date_time_immutable_column_0 | ||
| SQL, | ||
| ), | ||
| [ | ||
| 'date_time_immutable_column_0' => '2024-01-01 00:00:00', | ||
| ], | ||
| ]; | ||
|
|
||
| yield [ | ||
| [ | ||
| 'date_time_immutable_column' => new DateTimeImmutable('2024-01-01 00:00:00'), | ||
| ], | ||
| str_replace( | ||
| "\n", | ||
| ' ', | ||
| <<<SQL | ||
| SELECT __foo_table__.id, __foo_table__.date_time_immutable_column | ||
| FROM __foo_table__ __foo_table__ WHERE __foo_table__.date_time_immutable_column = ? | ||
| SQL, | ||
| ), | ||
| [ | ||
| 1 => '2024-01-01 00:00:00', | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @return \Ibexa\Contracts\CorePersistence\Gateway\AbstractDoctrineDatabase<array<mixed>> | ||
| */ | ||
| private function createDatabaseGateway(Connection $connection): AbstractDoctrineDatabase | ||
| { | ||
| $registry = $this->createMock(DoctrineSchemaMetadataRegistryInterface::class); | ||
|
|
||
| $metadata = new DoctrineSchemaMetadata( | ||
| $connection, | ||
| null, | ||
| '__foo_table__', | ||
| [ | ||
| 'id' => Types::INTEGER, | ||
| 'date_time_immutable_column' => Types::DATETIME_IMMUTABLE, | ||
| ], | ||
| ['id'], | ||
| ); | ||
|
|
||
| $registry->expects(self::atLeastOnce()) | ||
| ->method('getMetadataForTable') | ||
| ->with(self::identicalTo('__foo_table__')) | ||
| ->willReturn($metadata); | ||
|
|
||
| return new class($connection, $registry, $metadata) extends AbstractDoctrineDatabase { | ||
| private DoctrineSchemaMetadata $metadata; | ||
|
|
||
| public function __construct( | ||
| Connection $connection, | ||
| DoctrineSchemaMetadataRegistryInterface $registry, | ||
| DoctrineSchemaMetadata $metadata | ||
| ) { | ||
| parent::__construct($connection, $registry); | ||
| $this->metadata = $metadata; | ||
| } | ||
|
|
||
| protected function getTableName(): string | ||
| { | ||
| return '__foo_table__'; | ||
| } | ||
|
|
||
| protected function buildMetadata(): DoctrineSchemaMetadataInterface | ||
| { | ||
| return $this->metadata; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @return \Doctrine\DBAL\Connection&\PHPUnit\Framework\MockObject\MockObject | ||
| */ | ||
| private function createConnectionMock(): Connection | ||
| { | ||
| $connection = $this->createMock(Connection::class); | ||
| $connection->expects(self::once()) | ||
| ->method('createQueryBuilder') | ||
| ->willReturn(new QueryBuilder($connection)); | ||
|
|
||
| $connection->expects(self::atLeastOnce()) | ||
| ->method('getDatabasePlatform') | ||
| ->willReturn(new PostgreSQL94Platform()); | ||
|
|
||
| $connection->expects(self::atLeastOnce()) | ||
| ->method('getExpressionBuilder') | ||
| ->willReturn(new ExpressionBuilder($connection)); | ||
|
|
||
| return $connection; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.