class PathLocatorTest

@coversDefaultClass \Drupal\package_manager\PathLocator @group package_manager @internal

Hierarchy

Expanded class hierarchy of PathLocatorTest

File

core/modules/package_manager/tests/src/Unit/PathLocatorTest.php, line 16

Namespace

Drupal\Tests\package_manager\Unit
View source
class PathLocatorTest extends UnitTestCase {
    
    /**
     * @covers ::getStagingRoot
     */
    public function testStagingRoot() : void {
        $config_factory = $this->getConfigFactoryStub([
            'system.site' => [
                'uuid' => '_my_site_id',
            ],
        ]);
        $file_system = $this->prophesize(FileSystemInterface::class);
        $file_system->getTempDirectory()
            ->willReturn('/path/to/temp');
        $path_locator = new PathLocator('/path/to/drupal', $config_factory, $file_system->reveal());
        $this->assertSame('/path/to/temp/.package_manager_my_site_id', $path_locator->getStagingRoot());
    }
    
    /**
     * Data provider for ::testWebRoot().
     *
     * @return string[][]
     *   Sets of arguments to pass to the test method.
     */
    public static function providerWebRoot() : array {
        // In certain sites (like those created by drupal/recommended-project), the
        // web root is a subdirectory of the project, and exists next to the
        // vendor directory.
        return [
            'recommended project' => [
                '/path/to/project/www',
                '/path/to/project',
                'www',
            ],
            'recommended project with trailing slash on app root' => [
                '/path/to/project/www/',
                '/path/to/project',
                'www',
            ],
            'recommended project with trailing slash on project root' => [
                '/path/to/project/www',
                '/path/to/project/',
                'www',
            ],
            'recommended project with trailing slashes' => [
                '/path/to/project/www/',
                '/path/to/project/',
                'www',
            ],
            // In legacy projects (i.e., created by drupal/legacy-project), the
            // web root is the project root.
'legacy project' => [
                '/path/to/drupal',
                '/path/to/drupal',
                '',
            ],
            'legacy project with trailing slash on app root' => [
                '/path/to/drupal/',
                '/path/to/drupal',
                '',
            ],
            'legacy project with trailing slash on project root' => [
                '/path/to/drupal',
                '/path/to/drupal/',
                '',
            ],
            'legacy project with trailing slashes' => [
                '/path/to/drupal/',
                '/path/to/drupal/',
                '',
            ],
        ];
    }
    
    /**
     * Tests that the web root is computed correctly.
     *
     * @param string $app_root
     *   The absolute path of the Drupal root.
     * @param string $project_root
     *   The absolute path of the project root.
     * @param string $expected_web_root
     *   The value expected from getWebRoot().
     *
     * @covers ::getWebRoot
     *
     * @dataProvider providerWebRoot
     */
    public function testWebRoot(string $app_root, string $project_root, string $expected_web_root) : void {
        $path_locator = $this->getMockBuilder(PathLocator::class)
            ->onlyMethods([
            'getProjectRoot',
            'getStagingRoot',
            'getVendorDirectory',
        ])
            ->setConstructorArgs([
            $app_root,
            $this->getConfigFactoryStub(),
            $this->prophesize(FileSystemInterface::class)
                ->reveal(),
        ])
            ->getMock();
        $path_locator->method('getProjectRoot')
            ->willReturn($project_root);
        $this->assertSame($expected_web_root, $path_locator->getWebRoot());
    }

}

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.
PathLocatorTest::providerWebRoot public static function Data provider for ::testWebRoot().
PathLocatorTest::testStagingRoot public function @covers ::getStagingRoot
PathLocatorTest::testWebRoot public function Tests that the web root is computed correctly.
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 358
UnitTestCase::setUpBeforeClass public static function

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