function SandboxManagerBaseTest::testGetSandboxDirectory

@covers ::getSandboxDirectory

File

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

Class

SandboxManagerBaseTest
@coversDefaultClass \Drupal\package_manager\SandboxManagerBase[[api-linebreak]] @group package_manager @group #slow @internal

Namespace

Drupal\Tests\package_manager\Kernel

Code

public function testGetSandboxDirectory() : void {
  // In this test, we're working with paths that (probably) don't exist in
  // the file system at all, so we don't want to validate that the file system
  // is writable when creating stages.
  $validator = $this->container
    ->get(WritableFileSystemValidator::class);
  $this->container
    ->get('event_dispatcher')
    ->removeSubscriber($validator);
  /** @var \Drupal\package_manager_bypass\MockPathLocator $path_locator */
  $path_locator = $this->container
    ->get(PathLocator::class);
  $stage = $this->createStage();
  $id = $stage->create();
  $stage_dir = $stage->getSandboxDirectory();
  $this->assertStringStartsWith($path_locator->getStagingRoot() . '/', $stage_dir);
  $this->assertStringEndsWith("/{$id}", $stage_dir);
  // If the stage root directory is changed, the existing stage shouldn't be
  // affected...
  $active_dir = $path_locator->getProjectRoot();
  $new_staging_root = $this->testProjectRoot . DIRECTORY_SEPARATOR . 'junk';
  if (!is_dir($new_staging_root)) {
    mkdir($new_staging_root);
  }
  $path_locator->setPaths($active_dir, "{$active_dir}/vendor", '', $new_staging_root);
  $this->assertSame($stage_dir, $stage->getSandboxDirectory());
  $stage->destroy();
  // ...but a new stage should be.
  $stage = $this->createStage();
  $another_id = $stage->create();
  $this->assertNotSame($id, $another_id);
  $stage_dir = $stage->getSandboxDirectory();
  $this->assertStringStartsWith(realpath($new_staging_root), $stage_dir);
  $this->assertStringEndsWith("/{$another_id}", $stage_dir);
}

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