Skip to content

Commit

Permalink
test: fix tests that fails on Feb 29
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 29, 2024
1 parent 9894b92 commit 549db02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions tests/system/I18n/TimeLegacyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,15 @@ public function testGetTimestamp(): void

public function testGetAge(): void
{
// setTestNow() does not work to parse().
$time = TimeLegacy::parse('5 years ago');

$this->assertSame(5, $time->getAge());
$this->assertSame(5, $time->age);
// Considers leap year
$now = TimeLegacy::now();
$expected = ($now->day === '29' && $now->month === '2') ? 4 : 5;

$this->assertSame($expected, $time->getAge());
$this->assertSame($expected, $time->age);
}

public function testAgeNow(): void
Expand Down
9 changes: 7 additions & 2 deletions tests/system/I18n/TimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,15 @@ public function testGetTimestamp(): void
*/
public function testGetAge(): void
{
// setTestNow() does not work to parse().
$time = Time::parse('5 years ago');

$this->assertSame(5, $time->getAge());
$this->assertSame(5, $time->age);
// Considers leap year
$now = Time::now();
$expected = ($now->day === '29' && $now->month === '2') ? 4 : 5;

$this->assertSame($expected, $time->getAge());
$this->assertSame($expected, $time->age);
}

public function testAgeNow(): void
Expand Down

0 comments on commit 549db02

Please sign in to comment.