function FixtureManipulator::addProjectAtPath

Adds a project at a path.

Parameters

string $path: The path.

string|null $project_name: (optional) The project name. If none is specified the last part of the path will be used.

string|null $file_name: (optional) The file name. If none is specified the project name will be used.

File

core/modules/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php, line 266

Class

FixtureManipulator
Manipulates a test fixture using Composer commands.

Namespace

Drupal\fixture_manipulator

Code

public function addProjectAtPath(string $path, ?string $project_name = NULL, ?string $file_name = NULL) : self {
  if (!$this->committingChanges) {
    $this->queueManipulation('addProjectAtPath', func_get_args());
    return $this;
  }
  $path = $this->dir . "/{$path}";
  if (file_exists($path)) {
    throw new \LogicException("'{$path}' path already exists.");
  }
  $fs = new SymfonyFileSystem();
  $fs->mkdir($path);
  if ($project_name === NULL) {
    $project_name = basename($path);
  }
  if ($file_name === NULL) {
    $file_name = "{$project_name}.info.yml";
  }
  assert(file_put_contents("{$path}/{$file_name}", Yaml::encode([
    'project' => $project_name,
  ])) !== FALSE);
  return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.