diff --git a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php index 3db5906..5e50b96 100644 --- a/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php +++ b/core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulChanged.php @@ -83,9 +83,13 @@ public function save() { * Simulates passage of one second. */ protected function waitASecond() { - /** @var \Drupal\entity_test\TimeTest $timeService */ - $timeService = \Drupal::time(); - $timeService->increment('requestTime'); + /** @var \Drupal\Tests\TimeTestHelper $time_service */ + $time_service = \Drupal::time(); + + $request_time = $time_service->getRequestTime(); + $request_time += 1; + + $time_service->setRequestTime($request_time); } } diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestServiceProvider.php b/core/modules/system/tests/modules/entity_test/src/EntityTestServiceProvider.php index 8f5d8f6..661c36f 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestServiceProvider.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestServiceProvider.php @@ -12,7 +12,7 @@ class EntityTestServiceProvider extends ServiceProviderBase { */ public function alter(ContainerBuilder $container) { $timeService = $container->getDefinition('datetime.time'); - $timeService->setClass('Drupal\entity_test\TimeShifter'); + $timeService->setClass('Drupal\Tests\TimeTestHelper'); } } diff --git a/core/modules/system/tests/modules/entity_test/src/TimeShifter.php b/core/tests/Drupal/Tests/TimeTestHelper.php similarity index 50% rename from core/modules/system/tests/modules/entity_test/src/TimeShifter.php rename to core/tests/Drupal/Tests/TimeTestHelper.php index 0f22068..0b50651 100644 --- a/core/modules/system/tests/modules/entity_test/src/TimeShifter.php +++ b/core/tests/Drupal/Tests/TimeTestHelper.php @@ -1,10 +1,10 @@ $property === NULL) { - // Initialize local counter when incrementing for the first time. - $getter = 'get' . ucfirst($property); - $this->$property = $this->$getter(); - } - - $this->$property += $amount; - } - - /** * {@inheritdoc} */ public function getRequestTime() { if ($this->requestTime === NULL) { return parent::getRequestTime(); - } else { + } + else { return $this->requestTime; } } @@ -60,10 +42,11 @@ public function getRequestTime() { * {@inheritdoc} */ public function getRequestMicroTime() { - if ($this->currentMicroTime === NULL) { + if ($this->requestMicroTime === NULL) { return parent::getRequestMicroTime(); - } else { - $this->currentMicroTime; + } + else { + return $this->requestMicroTime; } } @@ -73,7 +56,8 @@ public function getRequestMicroTime() { public function getCurrentTime() { if ($this->currentTime === NULL) { return parent::getCurrentTime(); - } else { + } + else { return $this->currentTime; } } @@ -84,9 +68,46 @@ public function getCurrentTime() { public function getCurrentMicroTime() { if ($this->currentMicroTime === NULL) { return parent::getCurrentMicroTime(); - } else { - $this->currentMicroTime; } + else { + return $this->currentMicroTime; + } + } + + /** + * Sets the request time. + * + * @param int $request_time + */ + public function setRequestTime($request_time) { + $this->requestTime = $request_time; + } + + /** + * Sets the request time, with microseconds. + * + * @param float $request_micro_time + */ + public function setRequestMicroTime($request_micro_time) { + $this->requestMicroTime = $request_micro_time; + } + + /** + * Sets the current time. + * + * @param int $current_time + */ + public function setCurrentTime($current_time) { + $this->currentTime = $current_time; + } + + /** + * Sets the current time, with microseconds. + * + * @param int $current_micro_time + */ + public function setCurrentMicroTime($current_micro_time) { + $this->currentMicroTime = $current_micro_time; } }