class ComponentsIsolatedBuildTest

Same name in other branches
  1. 10 core/tests/Drupal/BuildTests/Composer/Component/ComponentsIsolatedBuildTest.php \Drupal\BuildTests\Composer\Component\ComponentsIsolatedBuildTest
  2. 11.x core/tests/Drupal/BuildTests/Composer/Component/ComponentsIsolatedBuildTest.php \Drupal\BuildTests\Composer\Component\ComponentsIsolatedBuildTest

Try to install dependencies per component, using Composer.

@group #slow @group Composer @group Component

@coversNothing

@requires externalCommand composer

Hierarchy

Expanded class hierarchy of ComponentsIsolatedBuildTest

File

core/tests/Drupal/BuildTests/Composer/Component/ComponentsIsolatedBuildTest.php, line 19

Namespace

Drupal\BuildTests\Composer\Component
View source
class ComponentsIsolatedBuildTest extends ComposerBuildTestBase {
    
    /**
     * Provides an array with relative paths to the component paths.
     *
     * @return array
     *   An array with relative paths to the component paths.
     */
    public function provideComponentPaths() : array {
        $data = [];
        // During the dataProvider phase, there is not a workspace directory yet.
        // So we will find relative paths and assemble them with the workspace
        // path later.
        $drupal_root = $this->getDrupalRoot();
        $composer_json_finder = $this->getComponentPathsFinder($drupal_root);
        
        /** @var \Symfony\Component\Finder\SplFileInfo $path */
        foreach ($composer_json_finder->getIterator() as $path) {
            $data[] = [
                '/' . $path->getRelativePath(),
            ];
        }
        return $data;
    }
    
    /**
     * Test whether components' composer.json can be installed in isolation.
     *
     * @dataProvider provideComponentPaths
     */
    public function testComponentComposerJson(string $component_path) : void {
        // Only copy the components. Copy all of them because some of them depend on
        // each other.
        $finder = $this->getCodebaseFinder();
        $finder->in($this->getDrupalRoot() . static::$componentsPath);
        $this->copyCodebase($finder->getIterator());
        $working_dir = $this->getWorkingPath() . static::$componentsPath . $component_path;
        // We add path repositories so we can wire internal dependencies together.
        $this->addExpectedRepositories($working_dir);
        // Perform the installation.
        $this->executeCommand("composer install --working-dir={$working_dir} --no-interaction --no-progress");
        $this->assertCommandSuccessful();
    }
    
    /**
     * Adds expected repositories as path repositories to package under test.
     *
     * @param string $working_dir
     *   The working directory.
     */
    protected function addExpectedRepositories(string $working_dir) : void {
        $repo_paths = [
            'Render' => 'drupal/core-render',
            'Utility' => 'drupal/core-utility',
        ];
        foreach ($repo_paths as $path => $package_name) {
            $path_repo = $this->getWorkingPath() . static::$componentsPath . '/' . $path;
            $repo_name = strtolower($path);
            // Add path repositories with the current version number to the current
            // package under test.
            $drupal_version = Composer::drupalVersionBranch();
            $this->executeCommand("composer config repositories.{$repo_name} " . "'{\"type\": \"path\",\"url\": \"{$path_repo}\",\"options\": {\"versions\": {\"{$package_name}\": \"{$drupal_version}\"}}}' --working-dir={$working_dir}");
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
BuildTestBase::$commandProcess private property The most recent command process.
BuildTestBase::$destroyBuild protected property Default to destroying build artifacts after a test finishes.
BuildTestBase::$hostName private static property Our native host name, used by PHP when it starts up the server.
BuildTestBase::$hostPort private property Port that will be tested.
BuildTestBase::$mink private property The Mink session manager.
BuildTestBase::$phpFinder private property The PHP executable finder.
BuildTestBase::$portLocks private property A list of ports used by the test.
BuildTestBase::$serverDocroot private property The docroot for the server process.
BuildTestBase::$serverProcess private property The process that's running the HTTP server.
BuildTestBase::$workspaceDir private property The working directory where this test will manipulate files.
BuildTestBase::assertCommandExitCode public function Asserts that the last command returned the specified exit code.
BuildTestBase::assertCommandOutputContains public function Assert that text is present in the output of the most recent command.
BuildTestBase::assertCommandSuccessful public function Asserts that the last command ran without error.
BuildTestBase::assertDrupalVisit public function Helper function to assert that the last visit was a Drupal site.
BuildTestBase::assertErrorOutputContains public function Assert that text is present in the error output of the most recent command.
BuildTestBase::assertErrorOutputNotContains public function Assert text is not present in the error output of the most recent command.
BuildTestBase::checkPortIsAvailable protected function Checks whether a port is available.
BuildTestBase::copyCodebase public function Copy the current working codebase into a workspace.
BuildTestBase::executeCommand public function Run a command.
BuildTestBase::findAvailablePort protected function Discover an available port number.
BuildTestBase::getCodebaseFinder public function Get a default Finder object for a Drupal codebase.
BuildTestBase::getDrupalRoot protected function Get the root path of this Drupal codebase.
BuildTestBase::getMink public function Get the Mink instance.
BuildTestBase::getPortNumber protected function Get the port number for requests.
BuildTestBase::getWorkingPath protected function Get the working directory within the workspace, creating if necessary.
BuildTestBase::getWorkspaceDirectory public function Full path to the workspace where this test can build.
BuildTestBase::initMink protected function Set up the Mink session manager.
BuildTestBase::instantiateServer protected function Do the work of making a server process.
BuildTestBase::setUp protected function 2
BuildTestBase::setUpBeforeClass public static function
BuildTestBase::standUpServer protected function Makes a local test server using PHP's internal HTTP server.
BuildTestBase::stopServer protected function Stop the HTTP server, zero out all necessary variables.
BuildTestBase::tearDown protected function 1
BuildTestBase::visit public function Visit a URI on the HTTP server.
ComponentsIsolatedBuildTest::addExpectedRepositories protected function Adds expected repositories as path repositories to package under test.
ComponentsIsolatedBuildTest::provideComponentPaths public function Provides an array with relative paths to the component paths.
ComponentsIsolatedBuildTest::testComponentComposerJson public function Test whether components' composer.json can be installed in isolation.
ComposerBuildTestBase::$componentsPath protected static property Relative path from Drupal root to the Components directory.
ComposerBuildTestBase::assertDrupalVersion protected function Assert that the VERSION constant in Drupal.php is the expected value.
ComposerBuildTestBase::getComponentPathsFinder protected function Find all the composer.json files for components.
ExternalCommandRequirementsTrait::$existingCommands private static property A list of existing external commands we've already discovered.
ExternalCommandRequirementsTrait::checkClassCommandRequirements private static function Checks whether required external commands are available per test class.
ExternalCommandRequirementsTrait::checkExternalCommandRequirements private static function Checks missing external command requirements.
ExternalCommandRequirementsTrait::checkMethodCommandRequirements private static function Checks whether required external commands are available per method.
ExternalCommandRequirementsTrait::externalCommandIsAvailable private static function Determine if an external command is available. 3
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.

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