forked from doctrine/dbal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 bugfix/doctrine#6261 - Allow (also for DATETIME) dynamic intervals …
…in DATE_ADD & DATE_SUB for SQLite - ✅ Add related functional test
- Loading branch information
1 parent
843719c
commit 1a09101
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,103 @@ | ||
<?php | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Ticket; | ||
|
||
use Doctrine\DBAL\Exception; | ||
use Doctrine\DBAL\Platforms\SqlitePlatform; | ||
use Doctrine\DBAL\Schema\SchemaException; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
use Doctrine\DBAL\Types\Types; | ||
|
||
class DBAL6261Test extends FunctionalTestCase | ||
{ | ||
/** @throws Exception */ | ||
protected function setUp(): void | ||
{ | ||
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { | ||
return; | ||
} | ||
|
||
self::markTestSkipped('Related to SQLite only'); | ||
} | ||
|
||
/** | ||
* @throws SchemaException | ||
* @throws Exception | ||
*/ | ||
public function testUnsignedIntegerDetection(): void | ||
{ | ||
$testTable = 'dbal6261tbl'; | ||
$testTableService = $testTable . '_service'; | ||
$testTableAgency = $testTable . '_agency'; | ||
|
||
$tableService = new Table($testTableService); | ||
$tableService->addColumn('id', Types::INTEGER); | ||
$tableService->addColumn('end_at', Types::DATETIME_MUTABLE); | ||
$tableService->addColumn('agency_id', Types::INTEGER); | ||
$tableService->setPrimaryKey(['id']); | ||
|
||
$tableAgency = new Table($testTableAgency); | ||
$tableAgency->addColumn('id', Types::INTEGER); | ||
$tableAgency->addColumn('utc_offset', Types::INTEGER); | ||
$tableAgency->setPrimaryKey(['id']); | ||
|
||
$this->dropAndCreateTable($tableService); | ||
$this->dropAndCreateTable($tableAgency); | ||
|
||
$this->connection->insert($testTableAgency, [ | ||
'id' => 1, | ||
'utc_offset' => 120, | ||
]); | ||
|
||
$match1 = [ | ||
'id' => 1, | ||
'end_at' => '2023-01-05 16:59:59', | ||
'agency_id' => 1, | ||
]; | ||
$match2 = [ | ||
'id' => 2, | ||
'end_at' => '2023-01-05 17:00:00', | ||
'agency_id' => 1, | ||
]; | ||
$wontMatch1 = [ | ||
'id' => 3, | ||
'end_at' => '2023-01-05 17:00:01', | ||
'agency_id' => 1, | ||
]; | ||
|
||
$this->connection->insert($testTableService, $match1); | ||
$this->connection->insert($testTableService, $match2); | ||
$this->connection->insert($testTableService, $wontMatch1); | ||
|
||
$platfom = $this->connection->getDatabasePlatform(); | ||
$qb = $this->connection->createQueryBuilder() | ||
->select('s.*') | ||
->from($testTableService, 's') | ||
->leftJoin('s', $testTableAgency, 'a', 's.agency_id = a.id') | ||
->where( | ||
's.end_at <= ' . $platfom->getDateAddMinutesExpression( | ||
"DATETIME('2023-01-05 15:00:00')", | ||
'a.utc_offset', | ||
), | ||
); | ||
$sql = $qb | ||
->getSQL(); | ||
self::assertEquals( | ||
'SELECT s.* FROM dbal6261tbl_service s ' | ||
. 'LEFT JOIN dbal6261tbl_agency a ON s.agency_id = a.id ' | ||
. "WHERE s.end_at <= DATETIME(DATETIME('2023-01-05 15:00:00'),'+' || a.utc_offset || ' MINUTE')", | ||
$sql, | ||
); | ||
|
||
$result = $qb->fetchAllAssociative(); | ||
|
||
self::assertEquals( | ||
[ | ||
$match1, | ||
$match2, | ||
], | ||
$result, | ||
); | ||
} | ||
} |