Skip to content

Commit

Permalink
Adapt test logic to PHP and SQLite II (#9442)
Browse files Browse the repository at this point in the history
In a88242e, testDateSub() was modified
in order to satisfy different opinions to the question "What is now
minus one month", that has different answers for different pieces of
software on March 30th.

Today, we are January 30th, we need to do the same for testDateAdd().
Hopefully this is the last time we hear about this.
  • Loading branch information
greg0ire committed Jan 30, 2022
1 parent c1b131b commit f9c3470
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/QueryDqlFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,18 @@ public function testDateAdd(string $unit, int $amount, int $delta = 0): void
self::assertArrayHasKey('now', $result);
self::assertArrayHasKey('add', $result);

$now = new DateTimeImmutable($result['now']);
$inOneUnit = $now->modify(sprintf('+%d %s', $amount, $unit));
if (
$unit === 'month'
&& $inOneUnit->format('m') === $now->modify('+2 month')->format('m')
&& ! $this->_em->getConnection()->getDatabasePlatform() instanceof SqlitePlatform
) {
$inOneUnit = new DateTimeImmutable('last day of next month');
}

self::assertEqualsWithDelta(
(new DateTimeImmutable($result['now']))->modify(sprintf('+%d %s', $amount, $unit)),
$inOneUnit,
new DateTimeImmutable($result['add']),
$delta
);
Expand Down

0 comments on commit f9c3470

Please sign in to comment.