-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Orisai\Clock\Adapter; | ||
|
||
use Orisai\Clock\Clock; | ||
use Psr\Clock\ClockInterface; | ||
use Symfony\Component\Clock\ClockInterface as SymfonyClock; | ||
|
||
final class ClockAdapterFactory | ||
{ | ||
|
||
public static function create(ClockInterface $clock): Clock | ||
{ | ||
if ($clock instanceof Clock) { | ||
return $clock; | ||
} | ||
|
||
if ($clock instanceof SymfonyClock) { | ||
Check warning on line 18 in src/Adapter/ClockAdapterFactory.php GitHub Actions / Test for mutants (ubuntu-latest, 8.1)
|
||
return new SymfonyToOrisaiClockAdapter($clock); | ||
} | ||
|
||
return new PsrToOrisaiClockAdapter($clock); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Orisai\Clock\Unit\Adapter; | ||
|
||
use DateTimeImmutable; | ||
use Generator; | ||
use Orisai\Clock\Adapter\ClockAdapterFactory; | ||
use Orisai\Clock\Adapter\PsrToOrisaiClockAdapter; | ||
use Orisai\Clock\FrozenClock; | ||
use Orisai\Clock\SystemClock; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Clock\ClockInterface; | ||
use Symfony\Component\Clock\ClockInterface as SymfonyClock; | ||
use Symfony\Component\Clock\NativeClock; | ||
use function class_exists; | ||
|
||
final class ClockAdapterFactoryTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @param class-string<ClockInterface> $class | ||
* | ||
* @dataProvider provide | ||
*/ | ||
public function test(ClockInterface $clock, string $class): void | ||
{ | ||
self::assertInstanceOf( | ||
$class, | ||
ClockAdapterFactory::create($clock), | ||
); | ||
} | ||
|
||
public function provide(): Generator | ||
{ | ||
yield [ | ||
new class implements ClockInterface { | ||
|
||
public function now(): DateTimeImmutable | ||
{ | ||
return new DateTimeImmutable(); | ||
} | ||
|
||
}, | ||
PsrToOrisaiClockAdapter::class, | ||
]; | ||
|
||
yield [ | ||
new FrozenClock(0), | ||
FrozenClock::class, | ||
]; | ||
|
||
yield [ | ||
new SystemClock(), | ||
SystemClock::class, | ||
]; | ||
|
||
if (class_exists(SymfonyClock::class)) { | ||
yield [ | ||
new NativeClock(), | ||
NativeClock::class, | ||
]; | ||
} | ||
} | ||
|
||
} |