Skip to content

Commit

Permalink
rename methods for the clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBadura committed May 20, 2022
1 parent da785ab commit 496a919
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Clock/Clock.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

interface Clock
{
public function createDateTimeImmutable(): DateTimeImmutable;
public function create(): DateTimeImmutable;
}
4 changes: 2 additions & 2 deletions src/Clock/FreezeClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Clock/SystemClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class SystemClock implements Clock
{
public function createDateTimeImmutable(): DateTimeImmutable
public function create(): DateTimeImmutable
{
return new DateTimeImmutable();
}
Expand Down
2 changes: 1 addition & 1 deletion src/EventBus/Decorator/RecordedOnDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
10 changes: 5 additions & 5 deletions tests/Unit/Clock/FreezeClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Clock/SystemClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 496a919

Please sign in to comment.