class InstalledPackageTest
@coversDefaultClass \Drupal\package_manager\InstalledPackage
@group package_manager
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\package_manager\Unit\InstalledPackageTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of InstalledPackageTest
File
-
core/
modules/ package_manager/ tests/ src/ Unit/ InstalledPackageTest.php, line 15
Namespace
Drupal\Tests\package_manager\UnitView source
class InstalledPackageTest extends UnitTestCase {
/**
* @covers ::createFromArray
*
* @depends testMetapackageWithAPath
*/
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(),
]);
}
/**
* @covers ::createFromArray
*/
public function testMetapackageWithAPath() : void {
$this->expectException(\AssertionError::class);
$this->expectExceptionMessage('Metapackage install path must be NULL.');
InstalledPackage::createFromArray([
'name' => 'vendor/test',
'type' => 'metapackage',
'version' => '1.0.0',
'path' => __DIR__,
]);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
InstalledPackageTest::testMetapackageWithAPath | public | function | @covers ::createFromArray | |
InstalledPackageTest::testPathResolution | public | function | @covers ::createFromArray | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUp | protected | function | 367 | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.