TestTime.php in Automatic Updates 8.2
File
tests/modules/automatic_updates_test/src/Datetime/TestTime.php
View source
<?php
namespace Drupal\automatic_updates_test\Datetime;
use Drupal\Component\Datetime\Time;
use Symfony\Component\HttpFoundation\RequestStack;
class TestTime extends Time {
protected $decoratorTime;
public function __construct(Time $time, RequestStack $request_stack) {
$this->decoratorTime = $time;
parent::__construct($request_stack);
}
public function getRequestTime() : int {
if ($faked_date = \Drupal::state()
->get('automatic_updates_test.fake_date_time')) {
return \DateTime::createFromFormat('U', $faked_date)
->getTimestamp();
}
return $this->decoratorTime
->getRequestTime();
}
public static function setFakeTimeByOffset(string $offset) : void {
$fake_time = (new \DateTime())
->modify($offset)
->format('U');
\Drupal::state()
->set('automatic_updates_test.fake_date_time', $fake_time);
}
}
Classes
Name |
Description |
TestTime |
Test service for altering the request time. |