Unverified Commit f9b616d5 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3579253 run-tests.sh does not properly process PHPUnit output when no...

fix: #3579253 run-tests.sh does not properly process PHPUnit output when no test are executed for a class

By: mondrake
By: smustgrave
parent 1f48cce9
Loading
Loading
Loading
Loading
Loading
+20 −19
Original line number Diff line number Diff line
@@ -138,8 +138,10 @@ public function processPhpUnitOnSingleTestClassOutcome(
    }

    // If not passed, add full PHPUnit run output since individual test cases
    // messages may not give full clarity (deprecations, warnings, etc.).
    if ($status > TestStatus::PASS) {
    // messages may not give full clarity (deprecations, warnings, etc.). Also,
    // PHPUnit returns success in case no tests are executed in the CLI, so
    // treat that as an error here.
    if ($status > TestStatus::PASS || $phpunit_results === []) {
      $message = $out;
      if (!empty($error)) {
        $message .= "\nERROR:\n";
@@ -160,7 +162,7 @@ public function processPhpUnitOnSingleTestClassOutcome(
    }

    $this->processPhpUnitResults($test_run, $phpunit_results);
    $summaries = $this->summarizeResults($phpunit_results);
    $summaries = $this->summarizeResults($test_class, $phpunit_results);

    return [
      'status' => $status,
@@ -325,6 +327,8 @@ public function processPhpUnitResults(TestRun $test_run, array $phpunit_results)
  /**
   * Tallies test results per test class.
   *
   * @param class-string $test_class
   *   The tested class name.
   * @param string[][] $results
   *   Array of results in the {simpletest} schema. Can be the return value of
   *   PhpUnitTestRunner::execute().
@@ -334,11 +338,9 @@ public function processPhpUnitResults(TestRun $test_run, array $phpunit_results)
   *
   * @internal
   */
  public function summarizeResults(array $results): array {
  public function summarizeResults(string $test_class, array $results): array {
    $summaries = [];
    foreach ($results as $result) {
      if (!isset($summaries[$result['test_class']])) {
        $summaries[$result['test_class']] = [
    $summaries[$test_class] = [
      '#pass' => 0,
      '#fail' => 0,
      '#error' => 0,
@@ -349,10 +351,9 @@ public function summarizeResults(array $results): array {
      '#time' => 0,
      '#exit_code' => 0,
    ];
      }

    foreach ($results as $result) {
      $summaries[$result['test_class']]['#time'] += $result['time'];

      switch ($result['status']) {
        case 'pass':
          $summaries[$result['test_class']]['#pass']++;
+33 −28
Original line number Diff line number Diff line
@@ -106,9 +106,9 @@ public function testXmlLogFilePath(): void {
    $this->assertStringEndsWith('phpunit-23.xml', $runner->xmlLogFilePath(23));
  }

  public static function providerTestSummarizeResults(): array {
    return [
      [
  public static function providerTestSummarizeResults(): \Generator {
    yield 'pass' => [
      static::class,
      [
        [
          'test_class' => static::class,
@@ -117,8 +117,10 @@ public static function providerTestSummarizeResults(): array {
        ],
      ],
      '#pass',
      ],
      [
    ];

    yield 'fail' => [
      static::class,
      [
        [
          'test_class' => static::class,
@@ -127,8 +129,10 @@ public static function providerTestSummarizeResults(): array {
        ],
      ],
      '#fail',
      ],
      [
    ];

    yield 'exception' => [
      static::class,
      [
        [
          'test_class' => static::class,
@@ -137,8 +141,10 @@ public static function providerTestSummarizeResults(): array {
        ],
      ],
      '#exception',
      ],
      [
    ];

    yield 'debug' => [
      static::class,
      [
        [
          'test_class' => static::class,
@@ -147,7 +153,6 @@ public static function providerTestSummarizeResults(): array {
        ],
      ],
      '#debug',
      ],
    ];
  }

@@ -155,9 +160,9 @@ public static function providerTestSummarizeResults(): array {
   * Tests summarize results.
   */
  #[DataProvider('providerTestSummarizeResults')]
  public function testSummarizeResults(array $results, string $has_status): void {
  public function testSummarizeResults(string $test_class, array $results, string $has_status): void {
    $runner = new PhpUnitTestRunner($this->root, sys_get_temp_dir());
    $summary = $runner->summarizeResults($results);
    $summary = $runner->summarizeResults($test_class, $results);

    $this->assertArrayHasKey(static::class, $summary);
    $this->assertEquals(1, $summary[static::class][$has_status]);