Skip to content

Commit

Permalink
Merge pull request #1 from usabilla/feature/frozen-clock-setter
Browse files Browse the repository at this point in the history
Make FrozenClock mutable through setter
  • Loading branch information
lcobucci authored Jan 19, 2018
2 parents 2f772f4 + dd2a647 commit d11d20b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FrozenClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public function __construct(DateTimeImmutable $now)
$this->now = $now;
}

public function setTo(DateTimeImmutable $now): void
{
$this->now = $now;
}

public function now(): DateTimeImmutable
{
return $this->now;
Expand Down
19 changes: 19 additions & 0 deletions test/FrozenClockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,23 @@ public function nowShouldReturnAlwaysTheSameObject()
self::assertSame($now, $clock->now());
self::assertSame($now, $clock->now());
}

/**
* @test
*
* @covers \Lcobucci\Clock\FrozenClock::setTo
* @uses \Lcobucci\Clock\FrozenClock::__construct()
* @uses \Lcobucci\Clock\FrozenClock::now
*/
public function nowSetChangesTheObject()
{
$oldNow = new DateTimeImmutable();
$clock = new FrozenClock($oldNow);

$newNow = new DateTimeImmutable();
$clock->setTo($newNow);

self::assertNotSame($oldNow, $clock->now());
self::assertSame($newNow, $clock->now());
}
}

0 comments on commit d11d20b

Please sign in to comment.