Skip to content
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

test: fix TimeTest #8593

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading