Skip to content
Snippets Groups Projects
Commit 3e6b2027 authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Ted Bowman
Browse files

Issue #3239645 by kunal.sachdev: Change the datetime service in...

Issue #3239645 by kunal.sachdev: Change the datetime service in tests/modules/automatic_updates_test/automatic_updates_test.services.yml to a decorator
parent c25a0431
No related branches found
No related tags found
1 merge request!58Issue #3239645: Change the datetime service in tests/modules/automatic_updates_test/automatic_updates_test.services.yml to a decorator
...@@ -4,6 +4,7 @@ services: ...@@ -4,6 +4,7 @@ services:
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
arguments: ['@state'] arguments: ['@state']
datetime.time: automatic_updates_test.time:
class: Drupal\automatic_updates_test\Datetime\TestTime class: Drupal\automatic_updates_test\Datetime\TestTime
arguments: ['@request_stack'] decorates: datetime.time
arguments: ['@automatic_updates_test.time.inner','@request_stack']
...@@ -3,12 +3,33 @@ ...@@ -3,12 +3,33 @@
namespace Drupal\automatic_updates_test\Datetime; namespace Drupal\automatic_updates_test\Datetime;
use Drupal\Component\Datetime\Time; use Drupal\Component\Datetime\Time;
use Symfony\Component\HttpFoundation\RequestStack;
/** /**
* Test service for altering the request time. * Test service for altering the request time.
*/ */
class TestTime extends Time { 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} * {@inheritdoc}
*/ */
...@@ -16,7 +37,7 @@ class TestTime extends Time { ...@@ -16,7 +37,7 @@ class TestTime extends Time {
if ($faked_date = \Drupal::state()->get('automatic_updates_test.fake_date_time')) { if ($faked_date = \Drupal::state()->get('automatic_updates_test.fake_date_time')) {
return \DateTime::createFromFormat('U', $faked_date)->getTimestamp(); return \DateTime::createFromFormat('U', $faked_date)->getTimestamp();
} }
return parent::getRequestTime(); return $this->decoratorTime->getRequestTime();
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment