class ComponentsTaggedReleaseTest

Same name and namespace in other branches
  1. 9 core/tests/Drupal/BuildTests/Composer/Component/ComponentsTaggedReleaseTest.php \Drupal\BuildTests\Composer\Component\ComponentsTaggedReleaseTest
  2. 10 core/tests/Drupal/BuildTests/Composer/Component/ComponentsTaggedReleaseTest.php \Drupal\BuildTests\Composer\Component\ComponentsTaggedReleaseTest

Demonstrate that the Component generator responds to release tagging.

@group Composer @group Component

@coversNothing

Hierarchy

Expanded class hierarchy of ComponentsTaggedReleaseTest

File

core/tests/Drupal/BuildTests/Composer/Component/ComponentsTaggedReleaseTest.php, line 18

Namespace

Drupal\BuildTests\Composer\Component
View source
class ComponentsTaggedReleaseTest extends ComposerBuildTestBase {
  
  /**
   * Highly arbitrary version and constraint expectations.
   *
   * @return array
   *   - First element is the tag that should be applied to \Drupal::version.
   *   - Second element is the resulting constraint which should be present in
   *     the component core dependencies.
   */
  public static function providerVersionConstraint() : array {
    return [
      // [Tag, constraint]
'1.0.x-dev' => [
        '1.0.x-dev',
        '1.0.x-dev',
      ],
      '1.0.0-beta1' => [
        '1.0.0-beta1',
        '1.0.0-beta1',
      ],
      '1.0.0-rc1' => [
        '1.0.0-rc1',
        '1.0.0-rc1',
      ],
      '1.0.0' => [
        '1.0.0',
        '^1.0',
      ],
    ];
  }
  
  /**
   * Validate release tagging and regeneration of dependencies.
   *
   * @dataProvider providerVersionConstraint
   */
  public function testReleaseTagging(string $tag, string $constraint) : void {
    $this->copyCodebase();
    $drupal_root = $this->getWorkspaceDirectory();
    // Set the core version.
    Composer::setDrupalVersion($drupal_root, $tag);
    $this->assertDrupalVersion($tag, $drupal_root);
    // Emulate the release script.
    // @see https://github.com/xjm/drupal_core_release/blob/main/tag.sh
    $this->executeCommand("COMPOSER_ROOT_VERSION=\"{$tag}\" composer update drupal/core*");
    $this->assertCommandSuccessful();
    $this->assertErrorOutputContains('generateComponentPackages');
    // Find all the components.
    $component_finder = $this->getComponentPathsFinder($drupal_root);
    // Loop through all the component packages.
    /** @var \Symfony\Component\Finder\SplFileInfo $composer_json */
    foreach ($component_finder->getIterator() as $composer_json) {
      $composer_json_data = json_decode(file_get_contents($composer_json->getPathname()), TRUE);
      $requires = array_merge($composer_json_data['require'] ?? [], $composer_json_data['require-dev'] ?? []);
      // Required packages from drupal/core-* should have our constraint.
      foreach ($requires as $package => $req_constraint) {
        if (str_contains($package, 'drupal/core-')) {
          $this->assertEquals($constraint, $req_constraint);
        }
      }
    }
  }

}

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. 1
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::getComposerRoot public function Gets the path to the Composer root directory.
BuildTestBase::getDrupalRoot public function Get the root path of this Drupal codebase.
BuildTestBase::getDrupalRootStatic public static 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::getWorkingPathDrupalRoot public function Gets the working path for Drupal core.
BuildTestBase::getWorkspaceDirectory public function Full path to the workspace where this test can build.
BuildTestBase::getWorkspaceDrupalRoot public function Gets the path to Drupal root in the workspace directory.
BuildTestBase::initMink protected function Set up the Mink session manager.
BuildTestBase::instantiateServer protected function Do the work of making a server process. 1
BuildTestBase::setUp protected function 6
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 3
BuildTestBase::visit public function Visit a URI on the HTTP server. 1
ComponentsTaggedReleaseTest::providerVersionConstraint public static function Highly arbitrary version and constraint expectations.
ComponentsTaggedReleaseTest::testReleaseTagging public function Validate release tagging and regeneration of dependencies.
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 static function Find all the composer.json files for components.
RequiresComposerTrait::requiresComposer public static function #[BeforeClass]

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