function InstalledPackageTest::testPathResolution
@covers ::createFromArray
@depends testMetapackageWithAPath
File
-
core/
modules/ package_manager/ tests/ src/ Unit/ InstalledPackageTest.php, line 22
Class
- InstalledPackageTest
- @coversDefaultClass \Drupal\package_manager\InstalledPackage
Namespace
Drupal\Tests\package_manager\UnitCode
public function testPathResolution() : void {
// Metapackages must be created without a path.
$package = InstalledPackage::createFromArray([
'name' => 'vendor/test',
'type' => 'metapackage',
'version' => '1.0.0',
'path' => NULL,
]);
$this->assertNull($package->path);
// Paths should be converted to real paths.
$package = InstalledPackage::createFromArray([
'name' => 'vendor/test',
'type' => 'library',
'version' => '1.0.0',
'path' => __DIR__ . '/..',
]);
$this->assertSame(realpath(__DIR__ . '/..'), $package->path);
// If we provide a path that cannot be resolved to a real path, it should
// raise an error.
$this->expectException(\TypeError::class);
InstalledPackage::createFromArray([
'name' => 'vendor/test',
'type' => 'library',
'version' => '1.0.0',
'path' => $this->getRandomGenerator()
->string(),
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.