You are here

public function DeploymentStorageHandlerTest::testDeploymentStorageHandler in Build Hooks 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Kernel/DeploymentStorageHandlerTest.php \Drupal\Tests\build_hooks\Kernel\DeploymentStorageHandlerTest::testDeploymentStorageHandler()

Tests deployment storage handler.

File

tests/src/Kernel/DeploymentStorageHandlerTest.php, line 44

Class

DeploymentStorageHandlerTest
Defines a class for testing deployment storage handler.

Namespace

Drupal\Tests\build_hooks\Kernel

Code

public function testDeploymentStorageHandler() {
  $next = $this->storage
    ->getOrCreateNextDeploymentForEnvironment($this->environment);
  $this
    ->assertEquals(sprintf('First deployment for %s', $this->environment
    ->label()), $next
    ->label());
  $this
    ->assertFalse($next
    ->isDeployed());
  $this
    ->assertTrue($next
    ->get('deployed')
    ->isEmpty());
  $this
    ->assertTrue($next
    ->get('contents')
    ->isEmpty());
  $this
    ->assertTrue($next
    ->get('deleted')
    ->isEmpty());
  $entity = EntityTest::create([
    'name' => $this
      ->randomMachineName(),
  ]);
  $entity
    ->save();
  $new_next = $this->storage
    ->getOrCreateNextDeploymentForEnvironment($this->environment);
  $this
    ->assertNotEquals($next
    ->id(), $new_next
    ->id());
  $last = $this->storage
    ->getLastDeploymentForEnvironment($this->environment);
  $this
    ->assertEquals($next
    ->id(), $last
    ->id());
  $this
    ->assertTrue($last
    ->isDeployed());
  $this
    ->assertEquals(self::MOCK_TIME, $last->deployed->value);
  $this
    ->assertEquals($entity
    ->id(), $last->contents->entity
    ->id());
  $this
    ->assertEquals($entity
    ->getEntityTypeId(), $last->contents->entity
    ->getEntityTypeId());
  $this
    ->assertEquals(sprintf('Items changed since %s for %s', \Drupal::service('date.formatter')
    ->format(self::MOCK_TIME), $this->environment
    ->label()), $new_next
    ->label());
}