function ComposerInspectorTest::testMetapackagePath
Tests that the installed path of metapackages is always NULL.
@covers ::getInstalledPackagesList
@testWith [true, null, null] [true, "<PROJECT_ROOT>/another/directory", "Metapackage 'test/package' is installed at unexpected path: '<PROJECT_ROOT>/another/directory', expected NULL"] [false, null, null] [false, "<PROJECT_ROOT>", "Package 'test/package' cannot be installed at path: '<PROJECT_ROOT>'"]
Parameters
bool $is_metapackage: Whether the test package will be a metapackage.
string|null $install_path: The package install path that Composer should report. If NULL, the reported path will be unchanged. The token <PROJECT_ROOT> will be replaced with the project root.
string|null $exception_message: The expected exception message, or NULL if no exception should be thrown. The token <PROJECT_ROOT> will be replaced with the project root.
File
-
core/
modules/ package_manager/ tests/ src/ Kernel/ ComposerInspectorTest.php, line 374
Class
- ComposerInspectorTest
- @coversDefaultClass \Drupal\package_manager\ComposerInspector
Namespace
Drupal\Tests\package_manager\KernelCode
public function testMetapackagePath(bool $is_metapackage, ?string $install_path, ?string $exception_message) : void {
$inspector = new class ($this->container
->get(ComposerProcessRunnerInterface::class), $this->container
->get(ComposerIsAvailableInterface::class), $this->container
->get(PathFactoryInterface::class)) extends ComposerInspector {
/**
* The install path that Composer should report for `test/package`.
*
* If not set, the reported install path will not be changed.
*
* @var string
*/
public $packagePath;
/**
* {@inheritdoc}
*/
protected function show(string $working_dir) : array {
$data = parent::show($working_dir);
if ($this->packagePath) {
$data['test/package']['path'] = $this->packagePath;
}
return $data;
}
};
$project_root = $this->container
->get(PathLocator::class)
->getProjectRoot();
if ($install_path) {
$install_path = str_replace('<PROJECT_ROOT>', $project_root, $install_path);
// The install path must actually exist.
if (!is_dir($install_path)) {
$this->assertTrue(mkdir($install_path, 0777, TRUE));
}
$inspector->packagePath = $install_path;
}
(new ActiveFixtureManipulator())->addPackage([
'name' => 'test/package',
'type' => $is_metapackage ? 'metapackage' : 'library',
])
->commitChanges();
if ($exception_message) {
$this->expectException(\UnexpectedValueException::class);
$exception_message = str_replace('<PROJECT_ROOT>', $project_root, $exception_message);
$this->expectExceptionMessage($exception_message);
}
$list = $inspector->getInstalledPackagesList($project_root);
$this->assertArrayHasKey('test/package', $list);
// If the package is a metapackage, its path should be NULL.
$this->assertSame($is_metapackage, is_null($list['test/package']->path));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.