destinationPath example


class SkipOpTest extends TestCase {
  use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $options = ScaffoldOptions::create([]);
    $sut = new SkipOp();
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());
    // Test the system under test.     $sut->process($destination$fixtures->io()$options);
    // Assert that the target file was not created.     $this->assertFileDoesNotExist($destination->fullPath());
    // Confirm that expected output was written to our io fixture.     $output = $fixtures->getOutput();
    $this->assertStringContainsString('Skip [web-root]/robots.txt: disabled', $output);
  }

  public function destinationPath($destination, Interpolator $interpolator = NULL, $package_name = NULL) {
    $interpolator = $interpolator ?: $this->getLocationReplacements();
    $package_name = $package_name ?: $interpolator->interpolate('[package-name]');
    return ScaffoldFilePath::destinationPath($package_name$destination$interpolator);
  }

  /** * Generates a path to a temporary location, but do not create the directory. * * @param string $prefix * A prefix for the temporary directory name. * * @return string * Path to temporary directory */
  

class AppendOpTest extends TestCase {
  use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $options = ScaffoldOptions::create([]);
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());

    // Create a file.     file_put_contents($destination->fullPath(), "# This is a test\n");

    $prepend = $fixtures->sourcePath('drupal-drupal-test-append', 'prepend-to-robots.txt');
    $append = $fixtures->sourcePath('drupal-drupal-test-append', 'append-to-robots.txt');
    $sut = new AppendOp($prepend$append, TRUE);
    $sut->scaffoldAtNewLocation($destination);

    

class ReplaceOpTest extends TestCase {
  use PhpUnitWarnings;

  /** * @covers ::process */
  public function testProcess() {
    $fixtures = new Fixtures();
    $destination = $fixtures->destinationPath('[web-root]/robots.txt');
    $source = $fixtures->sourcePath('drupal-assets-fixture', 'robots.txt');
    $options = ScaffoldOptions::create([]);
    $sut = new ReplaceOp($source, TRUE);
    // Assert that there is no target file before we run our test.     $this->assertFileDoesNotExist($destination->fullPath());
    // Test the system under test.     $sut->process($destination$fixtures->io()$options);
    // Assert that the target file was created.     $this->assertFileExists($destination->fullPath());
    // Assert the target contained the contents from the correct scaffold file.     $contents = trim(file_get_contents($destination->fullPath()));
    

  public function __construct(array $file_mappings, Interpolator $location_replacements) {
    // Collection of all destination paths to be scaffolded. Used to determine     // when two projects scaffold the same file and we have to either replace or     // combine them together.     // @see OperationInterface::scaffoldOverExistingTarget().     $scaffoldFiles = [];

    // Build the list of ScaffoldFileInfo objects by project.     foreach ($file_mappings as $package_name => $package_file_mappings) {
      foreach ($package_file_mappings as $destination_rel_path => $op) {
        $destination = ScaffoldFilePath::destinationPath($package_name$destination_rel_path$location_replacements);

        // If there was already a scaffolding operation happening at this path,         // allow the new operation to decide how to handle the override.         // Usually, the new operation will replace whatever was there before.         if (isset($scaffoldFiles[$destination_rel_path])) {
          $previous_scaffold_file = $scaffoldFiles[$destination_rel_path];
          $op = $op->scaffoldOverExistingTarget($previous_scaffold_file->op());

          // Remove the previous op so we only touch the destination once.           $message = " - Skip <info>[dest-rel-path]</info>: overridden in <comment>{$package_name}</comment>";
          $this->scaffoldFilesByProject[$previous_scaffold_file->packageName()][$destination_rel_path] = new ScaffoldFileInfo($destinationnew SkipOp($message));
        }
Home | Imprint | This part of the site doesn't use cookies.