You are here

protected function LocalPackagesTrait::copyPackage in Automatic Updates 8.2

Copies a package's entire directory to another location.

The copies' paths will be stored so that they can be easily deleted by ::deleteCopiedPackages().

Parameters

string $source_dir: The path of the package directory to copy.

string|null $destination_dir: (optional) The directory to which the package should be copied. Will be suffixed with a random string to ensure uniqueness. If not given, the system temporary directory will be used.

Return value

string The path of the temporary copy.

See also

::deleteCopiedPackages()

1 call to LocalPackagesTrait::copyPackage()
UpdateTestBase::copyPackage in tests/src/Build/UpdateTestBase.php

File

tests/src/Traits/LocalPackagesTrait.php, line 67

Class

LocalPackagesTrait
Provides methods for interacting with installed Composer packages.

Namespace

Drupal\Tests\automatic_updates\Traits

Code

protected function copyPackage(string $source_dir, string $destination_dir = NULL) : string {
  Assert::assertDirectoryExists($source_dir);
  if (empty($destination_dir)) {
    $destination_dir = FileSystem::getOsTemporaryDirectory();
    Assert::assertNotEmpty($destination_dir);
    $destination_dir .= DIRECTORY_SEPARATOR;
  }
  $destination_dir = uniqid($destination_dir);
  Assert::assertDirectoryDoesNotExist($destination_dir);
  (new SymfonyFilesystem())
    ->mirror($source_dir, $destination_dir);
  array_push($this->copiedPackages, $destination_dir);
  return $destination_dir;
}