Add first unit test.
This commit is contained in:
parent
ef35c5aeba
commit
abbeca3e06
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,10 +1,15 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# PHP Unit tests
|
||||||
|
phpunit
|
||||||
|
.phpunit.result.cache
|
||||||
|
|
||||||
|
# Filesystem storage items
|
||||||
*.sqlite
|
*.sqlite
|
||||||
*.txt
|
*.txt
|
||||||
|
|
||||||
/docker-compose.yml
|
|
||||||
init_complete
|
|
||||||
storage/upload/css
|
storage/upload/css
|
||||||
|
|
||||||
|
# Testing stuff
|
||||||
|
/docker-compose.yml
|
||||||
scratch
|
scratch
|
31
tests/Framework/Util/UtilTest.php
Normal file
31
tests/Framework/Util/UtilTest.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class UtilTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRelativeTime(): void
|
||||||
|
{
|
||||||
|
$datetime = new DateTimeImmutable();
|
||||||
|
|
||||||
|
$oneMinuteAgo = $datetime->modify('-1 minute')->format('c');
|
||||||
|
$relativeTime = Util::relative_time($oneMinuteAgo);
|
||||||
|
$this->assertSame($relativeTime, "1 minute ago");
|
||||||
|
|
||||||
|
$twoHoursAgo = $datetime->modify('-2 hours')->format('c');
|
||||||
|
$relativeTime = Util::relative_time($twoHoursAgo);
|
||||||
|
$this->assertSame($relativeTime, "2 hours ago");
|
||||||
|
|
||||||
|
$threeDaysAgo = $datetime->modify('-3 days')->format('c');
|
||||||
|
$relativeTime = Util::relative_time($threeDaysAgo);
|
||||||
|
$this->assertSame($relativeTime, "3 days ago");
|
||||||
|
|
||||||
|
$fourMonthsAgo = $datetime->modify('-4 months')->format('c');
|
||||||
|
$relativeTime = Util::relative_time($fourMonthsAgo);
|
||||||
|
$this->assertSame($relativeTime, "4 months ago");
|
||||||
|
|
||||||
|
$fiveYearsAgo = $datetime->modify('-5 years')->format('c');
|
||||||
|
$relativeTime = Util::relative_time($fiveYearsAgo);
|
||||||
|
$this->assertSame($relativeTime, "5 years ago");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user