Skip to content

Instantly share code, notes, and snippets.

@fvdb
Last active January 5, 2017 11:21
Show Gist options
  • Save fvdb/209ab5e7a2cc9252681f76a5e31279e5 to your computer and use it in GitHub Desktop.
Save fvdb/209ab5e7a2cc9252681f76a5e31279e5 to your computer and use it in GitHub Desktop.
<?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