FakeTime.php 752 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Facade\Ignition\Tests\TestClasses;
  3. use DateTimeImmutable;
  4. use Facade\FlareClient\Time\Time;
  5. class FakeTime implements Time
  6. {
  7. /** @var \DateTimeImmutable */
  8. protected $dateTime;
  9. public function __construct(string $dateTime = null, $format = 'Y-m-d H:i:s')
  10. {
  11. if (! is_null($dateTime)) {
  12. $this->setCurrentTime($dateTime, $format);
  13. return;
  14. }
  15. $this->dateTime = new DateTimeImmutable();
  16. }
  17. public function getCurrentTime(): int
  18. {
  19. return $this->dateTime->getTimestamp();
  20. }
  21. public function setCurrentTime(string $dateTime, $format = 'Y-m-d H:i:s')
  22. {
  23. $this->dateTime = DateTimeImmutable::createFromFormat($format, $dateTime);
  24. }
  25. }