From 496a919ff69ac9c59774d823a968db5a52f3140f Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Fri, 20 May 2022 08:44:30 +0000 Subject: [PATCH] rename methods for the clocks --- src/Clock/Clock.php | 2 +- src/Clock/FreezeClock.php | 4 ++-- src/Clock/SystemClock.php | 2 +- src/EventBus/Decorator/RecordedOnDecorator.php | 2 +- tests/Unit/Clock/FreezeClockTest.php | 10 +++++----- tests/Unit/Clock/SystemClockTest.php | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Clock/Clock.php b/src/Clock/Clock.php index 50fed58c..7be4fad8 100644 --- a/src/Clock/Clock.php +++ b/src/Clock/Clock.php @@ -8,5 +8,5 @@ interface Clock { - public function createDateTimeImmutable(): DateTimeImmutable; + public function create(): DateTimeImmutable; } diff --git a/src/Clock/FreezeClock.php b/src/Clock/FreezeClock.php index 0372f3fa..518b3c35 100644 --- a/src/Clock/FreezeClock.php +++ b/src/Clock/FreezeClock.php @@ -14,7 +14,7 @@ public function __construct(private DateTimeImmutable $frozenDateTime) { } - public function freeze(DateTimeImmutable $frozenDateTime): void + public function update(DateTimeImmutable $frozenDateTime): void { $this->frozenDateTime = $frozenDateTime; } @@ -27,7 +27,7 @@ public function sleep(int $seconds): void $this->frozenDateTime = $this->frozenDateTime->modify(sprintf('+%s seconds', $seconds)); } - public function createDateTimeImmutable(): DateTimeImmutable + public function create(): DateTimeImmutable { return $this->frozenDateTime; } diff --git a/src/Clock/SystemClock.php b/src/Clock/SystemClock.php index a4c7ffe4..08d2c154 100644 --- a/src/Clock/SystemClock.php +++ b/src/Clock/SystemClock.php @@ -8,7 +8,7 @@ final class SystemClock implements Clock { - public function createDateTimeImmutable(): DateTimeImmutable + public function create(): DateTimeImmutable { return new DateTimeImmutable(); } diff --git a/src/EventBus/Decorator/RecordedOnDecorator.php b/src/EventBus/Decorator/RecordedOnDecorator.php index 1d09199b..51ea82c1 100644 --- a/src/EventBus/Decorator/RecordedOnDecorator.php +++ b/src/EventBus/Decorator/RecordedOnDecorator.php @@ -15,6 +15,6 @@ public function __construct(private readonly Clock $clock) public function __invoke(Message $message): Message { - return $message->withRecordedOn($this->clock->createDateTimeImmutable()); + return $message->withRecordedOn($this->clock->create()); } } diff --git a/tests/Unit/Clock/FreezeClockTest.php b/tests/Unit/Clock/FreezeClockTest.php index da8781d1..12f40325 100644 --- a/tests/Unit/Clock/FreezeClockTest.php +++ b/tests/Unit/Clock/FreezeClockTest.php @@ -16,7 +16,7 @@ public function testCreateDateTimeImmutableWithFrozenClock(): void $current = new DateTimeImmutable(); $clock = new FreezeClock($current); - $new = $clock->createDateTimeImmutable(); + $new = $clock->create(); self::assertSame($current, $new); } @@ -26,7 +26,7 @@ public function testSleep(): void $date1 = new DateTimeImmutable(); $clock = new FreezeClock($date1); $clock->sleep(1); - $date2 = $clock->createDateTimeImmutable(); + $date2 = $clock->create(); $diff = $date1->diff($date2); @@ -37,11 +37,11 @@ public function testReFreeze(): void { $date1 = new DateTimeImmutable(); $clock = new FreezeClock($date1); - $new1 = $clock->createDateTimeImmutable(); + $new1 = $clock->create(); $date2 = new DateTimeImmutable(); - $clock->freeze($date2); - $new2 = $clock->createDateTimeImmutable(); + $clock->update($date2); + $new2 = $clock->create(); self::assertSame($date1, $new1); self::assertSame($date2, $new2); diff --git a/tests/Unit/Clock/SystemClockTest.php b/tests/Unit/Clock/SystemClockTest.php index 6c438d3b..f935c642 100644 --- a/tests/Unit/Clock/SystemClockTest.php +++ b/tests/Unit/Clock/SystemClockTest.php @@ -14,7 +14,7 @@ class SystemClockTest extends TestCase public function testCreateDateTimeImmutable(): void { $before = new DateTimeImmutable(); - $date = (new SystemClock())->createDateTimeImmutable(); + $date = (new SystemClock())->create(); $after = new DateTimeImmutable(); self::assertGreaterThanOrEqual($before, $date);