Last active
January 5, 2017 11:21
-
-
Save fvdb/209ab5e7a2cc9252681f76a5e31279e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
final class UselessUnixTimestampProvider | |
{ | |
private $clock; | |
public function __construct(Clock $clock) | |
{ | |
$this->clock = $clock; | |
} | |
public function timestamp(): int | |
{ | |
return $this->clock->timestamp(); | |
} | |
} | |
interface Clock | |
{ | |
public functiom timestamp(): int; | |
} | |
final class SystemClock implements Clock | |
{ | |
public function timestamp(): int | |
{ | |
return time(); | |
} | |
} | |
final class FixedClock implements Clock | |
{ | |
public function timestamp(): int | |
{ | |
return 1483615054; | |
} | |
} | |
// In tests | |
$provider = new UselessUnixTimestampProvider(new FixedClock()); | |
// In production | |
$provider = new UselessUnixTimestampProvider(new SystemClock()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment