diff --git a/tests/modules/automatic_updates_test/automatic_updates_test.services.yml b/tests/modules/automatic_updates_test/automatic_updates_test.services.yml index 165cde6e6466c3845bae609085b47a0ed6cba823..f3ade6aa34622f4a640de7c1444e0f359ba57502 100644 --- a/tests/modules/automatic_updates_test/automatic_updates_test.services.yml +++ b/tests/modules/automatic_updates_test/automatic_updates_test.services.yml @@ -4,6 +4,11 @@ services: tags: - { name: event_subscriber } arguments: ['@state'] + automatic_updates_test.request.time: + class: Drupal\automatic_updates_test\EventSubscriber\RequestTimeRecorder + tags: + - { name: event_subscriber } + arguments: ['@state', '@datetime.time'] automatic_updates_test.time: class: Drupal\automatic_updates_test\Datetime\TestTime decorates: datetime.time diff --git a/tests/modules/automatic_updates_test/src/EventSubscriber/RequestTimeRecorder.php b/tests/modules/automatic_updates_test/src/EventSubscriber/RequestTimeRecorder.php new file mode 100644 index 0000000000000000000000000000000000000000..ce775c3b6db5ba56969e9f312d19595313a33099 --- /dev/null +++ b/tests/modules/automatic_updates_test/src/EventSubscriber/RequestTimeRecorder.php @@ -0,0 +1,65 @@ +<?php + +namespace Drupal\automatic_updates_test\EventSubscriber; + +use Drupal\Component\Datetime\TimeInterface; +use Drupal\Core\State\StateInterface; +use Drupal\package_manager\Event\PostApplyEvent; +use Drupal\package_manager\Event\PreApplyEvent; +use Drupal\package_manager\Event\StageEvent; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Records the request time during various events. + */ +class RequestTimeRecorder implements EventSubscriberInterface { + + /** + * The state service. + * + * @var \Drupal\Core\State\StateInterface + */ + protected $state; + + /** + * The time service. + * + * @var \Drupal\Component\Datetime\TimeInterface + */ + protected $time; + + /** + * Constructs a new instance. + * + * @param \Drupal\Core\State\StateInterface $state + * The state service. + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. + */ + public function __construct(StateInterface $state, TimeInterface $time) { + $this->state = $state; + $this->time = $time; + } + + /** + * Records the request time. + * + * @param \Drupal\package_manager\Event\StageEvent $event + * The event object. + */ + public function updateState(StageEvent $event) { + $key = get_class($event) . ' time'; + $this->state->set($key, $this->time->getRequestMicroTime()); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + return [ + PreApplyEvent::class => 'updateState', + PostApplyEvent::class => 'updateState', + ]; + } + +} diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php index 3a96b95756139732d0627cd2bcec1879840d7d7f..d037cc518dd7cf327f655295dd2c1b3f235a0dc8 100644 --- a/tests/src/Functional/UpdaterFormTest.php +++ b/tests/src/Functional/UpdaterFormTest.php @@ -584,6 +584,14 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $assert_session->pageTextContainsOnce('Update complete!'); // Confirm the site was returned to the original maintenance mode state. $this->assertMaintenanceMode($maintenance_mode_on); + // Confirm that the apply and post-apply operations happened in + // separate requests. + // @see \Drupal\automatic_updates_test\EventSubscriber\RequestTimeRecorder + $pre_apply_time = $state->get('Drupal\package_manager\Event\PreApplyEvent time'); + $post_apply_time = $state->get('Drupal\package_manager\Event\PostApplyEvent time'); + $this->assertNotEmpty($pre_apply_time); + $this->assertNotEmpty($post_apply_time); + $this->assertNotSame($pre_apply_time, $post_apply_time); } /**