class TestTime in Automatic Updates 8.2
Test service for altering the request time.
Hierarchy
- class \Drupal\Component\Datetime\Time implements TimeInterface
- class \Drupal\automatic_updates_test\Datetime\TestTime
Expanded class hierarchy of TestTime
1 file declares its use of TestTime
- ReadinessValidationTest.php in tests/
src/ Functional/ ReadinessValidationTest.php
1 string reference to 'TestTime'
- automatic_updates_test.services.yml in tests/
modules/ automatic_updates_test/ automatic_updates_test.services.yml - tests/modules/automatic_updates_test/automatic_updates_test.services.yml
1 service uses TestTime
- automatic_updates_test.time in tests/
modules/ automatic_updates_test/ automatic_updates_test.services.yml - Drupal\automatic_updates_test\Datetime\TestTime
File
- tests/
modules/ automatic_updates_test/ src/ Datetime/ TestTime.php, line 11
Namespace
Drupal\automatic_updates_test\DatetimeView source
class TestTime extends Time {
/**
* The time service.
*
* @var \Drupal\Component\Datetime\Time
*/
protected $decoratorTime;
/**
* Constructs an Updater object.
*
* @param \Drupal\Component\Datetime\Time $time
* The time service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The RequestStack object.
*/
public function __construct(Time $time, RequestStack $request_stack) {
$this->decoratorTime = $time;
parent::__construct($request_stack);
}
/**
* {@inheritdoc}
*/
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();
}
/**
* Sets a fake time from an offset that will be used in the test.
*
* @param string $offset
* A date/time offset string as used by \DateTime::modify.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestTime:: |
protected | property | The time service. | |
TestTime:: |
public | function |
Returns the timestamp for the current request. Overrides Time:: |
|
TestTime:: |
public static | function | Sets a fake time from an offset that will be used in the test. | |
TestTime:: |
public | function |
Constructs an Updater object. Overrides Time:: |
|
Time:: |
protected | property | The request stack. | |
Time:: |
public | function |
Returns the current system time with microsecond precision. Overrides TimeInterface:: |
|
Time:: |
public | function |
Returns the current system time as an integer. Overrides TimeInterface:: |
|
Time:: |
public | function |
Returns the timestamp for the current request with microsecond precision. Overrides TimeInterface:: |