Files
beste_clock/tests/Clock/MinuteClockTest.php
T
Andreas Heigl 731f4c9651 Implement forward compatible Clock-Interface
The stella-maris/clock package provides an interface based on the
currently proposed status of PSR20. Due to the inactivity of the PSR20 working
group this is a way to already provide interoperability while still
maintaining forward compatibility. When the current status of PSR20 will
be released at one point in time the stella-maris/clock package will
extend the PSR20 interface so that this package becomes immeadiately
PSR20 compatible without any further work necessary. In the long run the
stella-maris/clock package will then be marked deprecated so that people
can then use the PSR20 provided implementation.

Should the implementation of PSR20 change between now and a possible
release then this interface will still exist and a possible
implementation will need more code-changes anyhow so this interface will
still provide some way of interoperability.

The implementation of the PSR20 polyfill has been moved to the
stella-maris/clock interface which can be implemented independentyl from
PSR20 and might allow some interoperability before the working group of
the FIG manages to decide upon something.
2022-04-20 16:21:40 +02:00

67 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Beste\Clock\Tests;
use Beste\Clock\MinuteClock;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use StellaMaris\Clock\ClockInterface;
/**
* @internal
* @coversDefaultClass \Beste\Clock\MinuteClock
*/
final class MinuteClockTest extends TestCase
{
/**
* @test
*
* @covers ::__construct
* @covers ::wrapping
* @covers ::now
* @covers ::floor
*
* @uses \Beste\Clock\FrozenClock
*
* @dataProvider dateTimeStringProvider
*/
public function itDiscardsEverythingSmallerThanMinutes(string $format, string $input, string $expected): void
{
$mockClock = $this->createMock(ClockInterface::class);
$mockClock->method('now')->willReturn(new DateTimeImmutable($input));
// Just to be sure that the test input is valid ^^
self::assertSame($input, $mockClock->now()->format($format));
$clock = MinuteClock::wrapping($mockClock);
self::assertSame($expected, $clock->now()->format($format));
}
/**
* @return array<string, string[]>
*/
public function dateTimeStringProvider(): array
{
return [
'microseconds' => [
'Y-m-d H:i:s.u',
'2021-03-24 01:23:45.123456',
'2021-03-24 01:23:00.000000',
],
'milliseconds' => [
'Y-m-d H:i:s.v',
'2021-03-24 01:23:45.123',
'2021-03-24 01:23:00.000',
],
'seconds' => [
'Y-m-d H:i:s',
'2021-03-24 01:23:45',
'2021-03-24 01:23:00',
],
];
}
}