Skip to content

Commit

Permalink
Merge pull request #8593 from kenjis/test-fix-TimeTest
Browse files Browse the repository at this point in the history
test: fix TimeTest
  • Loading branch information
kenjis authored Mar 5, 2024
2 parents 4c7ca62 + a14ea36 commit a99787c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
17 changes: 11 additions & 6 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 All @@ -414,31 +419,31 @@ public function testAgeNow(): void

public function testAgeFuture(): void
{
TimeLegacy::setTestNow('June 20, 2022', 'America/Chicago');
TimeLegacy::setTestNow('June 20, 2022');
$time = TimeLegacy::parse('August 12, 2116 4:15:23pm');

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

public function testGetAgeSameDayOfBirthday(): void
{
TimeLegacy::setTestNow('December 31, 2022', 'America/Chicago');
TimeLegacy::setTestNow('December 31, 2022');
$time = TimeLegacy::parse('December 31, 2020');

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

public function testGetAgeNextDayOfBirthday(): void
{
TimeLegacy::setTestNow('January 1, 2022', 'America/Chicago');
TimeLegacy::setTestNow('January 1, 2022');
$time = TimeLegacy::parse('December 31, 2020');

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

public function testGetAgeBeforeDayOfBirthday(): void
{
TimeLegacy::setTestNow('December 30, 2021', 'America/Chicago');
TimeLegacy::setTestNow('December 30, 2021');
$time = TimeLegacy::parse('December 31, 2020');

$this->assertSame(0, $time->getAge());
Expand Down
17 changes: 11 additions & 6 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 All @@ -421,31 +426,31 @@ public function testAgeNow(): void

public function testAgeFuture(): void
{
Time::setTestNow('June 20, 2022', 'America/Chicago');
Time::setTestNow('June 20, 2022');
$time = Time::parse('August 12, 2116 4:15:23pm');

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

public function testGetAgeSameDayOfBirthday(): void
{
Time::setTestNow('December 31, 2022', 'America/Chicago');
Time::setTestNow('December 31, 2022');
$time = Time::parse('December 31, 2020');

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

public function testGetAgeNextDayOfBirthday(): void
{
Time::setTestNow('January 1, 2022', 'America/Chicago');
Time::setTestNow('January 1, 2022');
$time = Time::parse('December 31, 2020');

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

public function testGetAgeBeforeDayOfBirthday(): void
{
Time::setTestNow('December 30, 2021', 'America/Chicago');
Time::setTestNow('December 30, 2021');
$time = Time::parse('December 31, 2020');

$this->assertSame(0, $time->getAge());
Expand Down

0 comments on commit a99787c

Please sign in to comment.