ReplaceOp example


  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. */
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);
    // Confirm that expected output was written to our io fixture.     $output = $fixtures->getOutput();
    

  public function replaceOp($project_name$source) {
    $source_path = $this->sourcePath($project_name$source);
    return new ReplaceOp($source_path, TRUE);
  }

  /** * Creates an AppendOp fixture. * * @param string $project_name * The name of the project to fetch; $package_name is * "fixtures/$project_name". * @param string $source * The name of the asset; path is "assets/$source". * * @return \Drupal\Composer\Plugin\Scaffold\Operations\AppendOp * An append operation object. */
Home | Imprint | This part of the site doesn't use cookies.