Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kolb committed May 6, 2024
1 parent a065718 commit f70fdbe
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/Clock/FrozenClockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace DigitalCraftsman\DateTimePrecision\Clock;

use DigitalCraftsman\DateTimePrecision\Moment;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

#[CoversClass(FrozenClock::class)]
final class FrozenClockTest extends TestCase
{
#[Test]
public function freeze_works(): void
{
// -- Arrange
$clock = new FrozenClock();
$moment = Moment::fromStringInTimeZone('2024-05-06 08:00:00', new \DateTimeZone('Europe/Berlin'));

// -- Act
$clock->freeze($moment);

// -- Assert
self::assertSame($moment, $clock->now());
}
}
29 changes: 29 additions & 0 deletions tests/Clock/SystemClockTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace DigitalCraftsman\DateTimePrecision\Clock;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

/**
* Only very little that's possible to test here, so we do what's possible.
*/
#[CoversClass(SystemClock::class)]
final class SystemClockTest extends TestCase
{
#[Test]
public function now_works(): void
{
// -- Arrange
$clock = new SystemClock();

// -- Act
$moment = $clock->now();

// -- Assert
self::assertEquals($moment->dateTime->getTimezone(), new \DateTimeZone('UTC'));
}
}

0 comments on commit f70fdbe

Please sign in to comment.