fullPath example

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

    $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.

  public function __construct(ScaffoldFilePath $sourcePath$overwrite = TRUE) {
    $this->source = $sourcePath;
    $this->overwrite = $overwrite;
  }

  /** * {@inheritdoc} */
  protected function generateContents() {
    return file_get_contents($this->source->fullPath());
  }

  /** * {@inheritdoc} */
  public function process(ScaffoldFilePath $destination, IOInterface $io, ScaffoldOptions $options) {
    $fs = new Filesystem();
    $destination_path = $destination->fullPath();
    // Do nothing if overwrite is 'false' and a file already exists at the     // destination.     if ($this->overwrite === FALSE && file_exists($destination_path)) {
      
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);
  }

}

  protected function hasContent(ScaffoldFilePath $file = NULL) {
    if (!$file) {
      return FALSE;
    }
    $path = $file->fullPath();
    return is_file($path) && (filesize($path) > 0);
  }

  /** * Gets the file path of a package. * * Note that if we call getInstallPath on the root package, we get the * wrong answer (the installation manager thinks our package is in * vendor). We therefore add special checking for this case. * * @param \Composer\Package\PackageInterface $package * The package. * * @return string * The file path. */

  public function process(IOInterface $io, ScaffoldOptions $options) {
    return $this->op()->process($this->destination, $io$options);
  }

  /** * Returns TRUE if the target does not exist or has changed. * * @return bool */
  final public function hasChanged() {
    $path = $this->destination()->fullPath();
    if (!file_exists($path)) {
      return TRUE;
    }
    return $this->op()->contents() !== file_get_contents($path);
  }

}

  public function manageIgnored(array $files, ScaffoldOptions $options) {
    if (!$this->managementOfGitIgnoreEnabled($options)) {
      return;
    }

    // Accumulate entries to add to .gitignore, sorted into buckets based on the     // location of the .gitignore file the entry should be added to.     $add_to_git_ignore = [];
    foreach ($files as $scaffoldResult) {
      $path = $scaffoldResult->destination()->fullPath();
      $is_ignored = Git::checkIgnore($this->io, $path$this->dir);
      if (!$is_ignored) {
        $is_tracked = Git::checkTracked($this->io, $path$this->dir);
        if (!$is_tracked && $scaffoldResult->isManaged()) {
          $dir = realpath(dirname($path));
          $name = basename($path);
          $add_to_git_ignore[$dir][] = '/' . $name;
        }
      }
    }
    // Write out the .gitignore files one at a time.

  public function addInterpolationData(Interpolator $interpolator$name_prefix = '') {
    if (empty($name_prefix)) {
      $name_prefix = $this->type;
    }
    $data = [
      'package-name' => $this->packageName(),
      "{$name_prefix}-rel-path" => $this->relativePath(),
      "{$name_prefix}-full-path" => $this->fullPath(),
    ];
    $interpolator->addData($data);
  }

  /** * Interpolate a string using the data from this scaffold file info. * * @param string $name_prefix * (optional) Prefix to add before -rel-path and -full-path item names. * Defaults to path type provided when constructing this object. * * @return \Drupal\Composer\Plugin\Scaffold\Interpolator * An interpolator for making string replacements. */

  public static function generateAutoload(IOInterface $io$package_name$web_root$vendor) {
    $autoload_path = static::autoloadPath($package_name$web_root);
    // Calculate the relative path from the webroot (location of the project     // autoload.php) to the vendor directory.     $fs = new Filesystem();
    $relative_autoload_path = $fs->findShortestPath($autoload_path->fullPath(), "$vendor/autoload.php");
    file_put_contents($autoload_path->fullPath()static::autoLoadContents($relative_autoload_path));
    return new ScaffoldResult($autoload_path, TRUE);
  }

  /** * Determines whether or not the autoload file has been committed. * * @param \Composer\IO\IOInterface $io * IOInterface to write to. * @param string $package_name * The name of the package defining the autoload file (the root package). * @param string $web_root * The path to the web root. * * @return bool * True if autoload.php file exists and has been committed to the repository */
/** * @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();
    $this->assertStringContainsString('Copy [web-root]/robots.txt from assets/robots.txt', $output);
  }

  
$this->default = $default_path;
    $this->managed = TRUE;
  }

  /** * {@inheritdoc} */
  protected function generateContents() {
    // Fetch the prepend contents, if provided.     $prepend_contents = '';
    if (!empty($this->prepend)) {
      $prepend_contents = file_get_contents($this->prepend->fullPath()) . "\n";
    }
    // Fetch the append contents, if provided.     $append_contents = '';
    if (!empty($this->append)) {
      $append_contents = "\n" . file_get_contents($this->append->fullPath());
    }

    // Get the original contents, or the default data if the original is empty.     $original_contents = $this->originalContents;
    if (empty($original_contents) && !empty($this->default)) {
      $original_contents = file_get_contents($this->default->fullPath());
    }
Home | Imprint | This part of the site doesn't use cookies.