mirror of
https://github.com/beste/clock.git
synced 2026-10-17 19:27:35 +00:00
Move source and test files up one level
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Beste\Clock\Tests;
|
||||
|
||||
use Beste\Clock\FrozenClock;
|
||||
use Beste\Clock\WrappingClock;
|
||||
use DateTimeImmutable;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversDefaultClass \Beste\Clock\WrappingClock
|
||||
*/
|
||||
final class WrappingClockTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers ::__construct
|
||||
* @covers ::wrapping
|
||||
* @covers ::now
|
||||
*/
|
||||
public function itWrapsAClockInterface(): void
|
||||
{
|
||||
$clock = FrozenClock::fromUTC();
|
||||
|
||||
$wrappedClock = WrappingClock::wrapping($clock);
|
||||
|
||||
self::assertSame(
|
||||
$clock->now()->format(DATE_ATOM),
|
||||
$wrappedClock->now()->format(DATE_ATOM)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers ::wrapping
|
||||
*/
|
||||
public function itWrapsAnObjectWithANowMethod(): void
|
||||
{
|
||||
$now = FrozenClock::fromUTC()->now();
|
||||
|
||||
$clock = new class($now) {
|
||||
private DateTimeImmutable $now;
|
||||
|
||||
public function __construct(DateTimeImmutable $now)
|
||||
{
|
||||
$this->now = $now;
|
||||
}
|
||||
|
||||
public function now(): DateTimeImmutable
|
||||
{
|
||||
return $this->now;
|
||||
}
|
||||
};
|
||||
|
||||
$wrappedClock = WrappingClock::wrapping($clock);
|
||||
|
||||
self::assertSame(
|
||||
$now->format(DATE_ATOM),
|
||||
$wrappedClock->now()->format(DATE_ATOM)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers ::wrapping
|
||||
*/
|
||||
public function itRejectsObjectsWithANowMethodReturningANonDateTimeImmutable(): void
|
||||
{
|
||||
$clock = new class() {
|
||||
public function now(): string
|
||||
{
|
||||
return 'foo';
|
||||
}
|
||||
};
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('$clock->now() must return a DateTimeImmutable');
|
||||
|
||||
WrappingClock::wrapping($clock);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user