function SandboxManagerBaseTest::testLongLivedSandboxSubscriberTracksTime

Same name and namespace in other branches
  1. main core/modules/package_manager/tests/src/Kernel/SandboxManagerBaseTest.php \Drupal\Tests\package_manager\Kernel\SandboxManagerBaseTest::testLongLivedSandboxSubscriberTracksTime()

Tests that LongLivedSandboxSubscriber tracks the create event time.

@legacy-covers \Drupal\package_manager\EventSubscriber\LongLivedSandboxSubscriber

File

core/modules/package_manager/tests/src/Kernel/SandboxManagerBaseTest.php, line 590

Class

SandboxManagerBaseTest
Tests Drupal\package_manager\SandboxManagerBase.

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testLongLivedSandboxSubscriberTracksTime() : void {
  $state = $this->container
    ->get('state');
  // No timestamp should exist before any stage is created.
  $this->assertNull($state->get(LongLivedSandboxSubscriber::STATE_KEY));
  $stage = $this->createStage();
  $stage->create();
  // After creating a stage, the timestamp should be set.
  /** @var int $timestamp */
  $timestamp = $state->get(LongLivedSandboxSubscriber::STATE_KEY);
  $this->assertNotNull($timestamp);
  $this->assertIsInt($timestamp);
  $this->assertGreaterThan(0, $timestamp);
  $stage->destroy();
  // The timestamp should persist after destroy, since it tracks the age
  // of the long-lived sandbox directory.
  $this->assertSame($timestamp, $state->get(LongLivedSandboxSubscriber::STATE_KEY));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.