sourcePath example


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()));
    $this->assertEquals('# Test version of robots.txt from drupal/core.', $contents);
    

  protected function createReplaceOp(PackageInterface $package, OperationData $operation_data) {
    if (!$operation_data->hasPath()) {
      throw new \RuntimeException("'path' component required for 'replace' operations.");
    }
    $package_name = $package->getName();
    $package_path = $this->getPackagePath($package);
    $source = ScaffoldFilePath::sourcePath($package_name$package_path$operation_data->destination()$operation_data->path());
    $op = new ReplaceOp($source$operation_data->overwrite());
    return $op;
  }

  /** * Creates an 'append' (or 'prepend') scaffold op. * * @param \Composer\Package\PackageInterface $package * The package that relative paths will be relative from. * @param OperationData $operation_data * The parameter data for this operation object, i.e. the relative 'path'. * * @return \Drupal\Composer\Plugin\Scaffold\Operations\OperationInterface * A scaffold replace operation object. */

  public function sourcePath($project_name$source) {
    $package_name = "fixtures/{$project_name}";
    $source_rel_path = "assets/{$source}";
    $package_path = $this->projectFixtureDir($project_name);
    return ScaffoldFilePath::sourcePath($package_name$package_path, 'unknown', $source_rel_path);
  }

  /** * Gets an Interpolator with 'web-root' and 'package-name' set. * * Use in place of ManageOptions::getLocationReplacements(). * * @return \Drupal\Composer\Plugin\Scaffold\Interpolator * An interpolator with location replacements, including 'web-root'. * * @see \Drupal\Composer\Plugin\Scaffold\ManageOptions::getLocationReplacements() */

  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);

    $expected = <<<EOT # robots.txt fixture scaffolded from "file-mappings" in drupal-drupal-test-append composer.json fixture. # This content is prepended to the top of the existing robots.txt fixture. # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # This is a test # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # This content is appended to the bottom of the existing robots.txt fixture. # robots.txt fixture scaffolded from "file-mappings" in drupal-drupal-test-append composer.json fixture.
Home | Imprint | This part of the site doesn't use cookies.