Verified Commit 7afe7f58 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3225706 by joachim, Gauravmahlawat: rewrite...

Issue #3225706 by joachim, Gauravmahlawat: rewrite ComposerProjectTemplatesTest::testMinimumStabilityStrictness() so failures say which package fails

(cherry picked from commit 89571758)
parent dca093de
Loading
Loading
Loading
Loading
+38 −27
Original line number Diff line number Diff line
@@ -98,7 +98,44 @@ public function testMinimumStabilityStrictness() {
    //   to in the future accidentally commit a dependency that regresses our
    //   actual stability requirement without us explicitly changing this
    //   constant.
    $this->assertSame($this->getLowestDependencyStability(), static::MINIMUM_STABILITY);
    $root = $this->getDrupalRoot();
    $process = $this->executeCommand("composer --working-dir=$root info --format=json");
    $this->assertCommandSuccessful();
    $installed = json_decode($process->getOutput(), TRUE);

    // A lookup of the numerical position of each of the stability terms.
    $stability_order_indexes = array_flip(static::STABILITY_ORDER);

    $minimum_stability_order_index = $stability_order_indexes[static::MINIMUM_STABILITY];

    $exclude = [
      'drupal/core',
      'drupal/core-project-message',
      'drupal/core-vendor-hardening',
    ];
    foreach ($installed['installed'] as $project) {
      // Exclude dependencies that are required with "self.version", since
      // those stabilities will automatically match the corresponding Drupal
      // release.
      if (in_array($project['name'], $exclude, TRUE)) {
        continue;
      }

      $project_stability = VersionParser::parseStability($project['version']);
      $project_stability_order_index = $stability_order_indexes[$project_stability];

      $project_stabilities[$project['name']] = $project_stability;

      $this->assertGreaterThanOrEqual($minimum_stability_order_index, $project_stability_order_index, sprintf(
        "Dependency %s with stability %s does not meet minimum stability %s.",
        $project['name'],
        $project_stability,
        static::MINIMUM_STABILITY,
      ));
    }

    // At least one project should be at the minimum stability.
    $this->assertContains(static::MINIMUM_STABILITY, $project_stabilities);
  }

  /**
@@ -357,32 +394,6 @@ protected function makeVendorPackage($repository_path) {
    file_put_contents($repository_path, $json);
  }

  /**
   * Returns the stability of the least stable dependency.
   */
  protected function getLowestDependencyStability() {
    $root = $this->getDrupalRoot();
    $process = $this->executeCommand("composer --working-dir=$root info --format=json");
    $this->assertCommandSuccessful();
    $installed = json_decode($process->getOutput(), TRUE);

    $lowest_stability_order_index = count(static::STABILITY_ORDER);
    foreach ($installed['installed'] as $project) {
      // Exclude dependencies that are required with "self.version", since
      // those stabilities will automatically match the corresponding Drupal
      // release.
      $exclude = ['drupal/core', 'drupal/core-project-message', 'drupal/core-vendor-hardening'];
      if (!in_array($project['name'], $exclude, TRUE)) {
        $stability = VersionParser::parseStability($project['version']);
        $stability_order_index = array_search($stability, static::STABILITY_ORDER);
        $lowest_stability_order_index = min($lowest_stability_order_index, $stability_order_index);
      }
    }
    $lowest_stability = static::STABILITY_ORDER[$lowest_stability_order_index];

    return $lowest_stability;
  }

  /**
   * Returns the stability of the current core version.
   *