function SandboxManagerBaseTest::testMetadata

Tests metadata.

@legacy-covers ::getMetadata @legacy-covers ::setMetadata

File

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

Class

SandboxManagerBaseTest
Tests Drupal\package_manager\SandboxManagerBase.

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testMetadata() : void {
  $stage = $this->createStage();
  $stage->create();
  $this->assertNull($stage->getMetadata('new_key'));
  $stage->setMetadata('new_key', 'value');
  $this->assertSame('value', $stage->getMetadata('new_key'));
  $stage->destroy();
  // Ensure that metadata associated with the previous stage was deleted.
  $stage = $this->createStage();
  $stage->create();
  $this->assertNull($stage->getMetadata('new_key'));
  $stage->destroy();
  // Ensure metadata cannot be accessed or set unless the stage has been
  // claimed.
  $stage = $this->createStage();
  try {
    $stage->getMetadata('new_key');
    $this->fail('Expected an ownership exception, but none was thrown.');
  } catch (\LogicException $e) {
    $this->assertSame('Stage must be claimed before performing any operations on it.', $e->getMessage());
  }
  try {
    $stage->setMetadata('new_key', 'value');
    $this->fail('Expected an ownership exception, but none was thrown.');
  } catch (\LogicException $e) {
    $this->assertSame('Stage must be claimed before performing any operations on it.', $e->getMessage());
  }
}

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