Verified Commit cf0ae4ae authored by Dave Long's avatar Dave Long
Browse files

Issue #3483931 by mondrake: [CI] Use testdox and colors in tests spawned by run-tests.sh

(cherry picked from commit 6e60f0b5)
parent 03397e90
Loading
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -9,6 +9,8 @@
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

// cspell:ignore testdox

/**
 * Run PHPUnit-based tests.
 *
@@ -100,16 +102,24 @@ public function phpUnitCommand(): string {
   *   A fully qualified test class name.
   * @param string $log_junit_file_path
   *   A filepath to use for PHPUnit's --log-junit option.
   * @param int $status
   * @param int|null $status
   *   (optional) The exit status code of the PHPUnit process will be assigned
   *   to this variable.
   * @param string[] $output
   * @param string[]|null $output
   *   (optional) The output by running the phpunit command. If provided, this
   *   array will contain the lines output by the command.
   * @param bool $colors
   *   (optional) Whether to use colors in output. Defaults to FALSE.
   *
   * @internal
   */
  protected function runCommand(string $test_class_name, string $log_junit_file_path, ?int &$status = NULL, ?array &$output = NULL): void {
  protected function runCommand(
    string $test_class_name,
    string $log_junit_file_path,
    ?int &$status = NULL,
    ?array &$output = NULL,
    bool $colors = FALSE,
  ): void {
    global $base_url;
    // Setup an environment variable containing the database connection so that
    // functional tests can connect to the database.
@@ -130,9 +140,13 @@ protected function runCommand(string $test_class_name, string $log_junit_file_pa
    // Build the command line for the PHPUnit CLI invocation.
    $command = [
      $phpunit_bin,
      '--testdox',
      '--log-junit',
      $log_junit_file_path,
    ];
    if ($colors) {
      $command[] = '--colors=always';
    }

    // If the deprecation handler bridge is active, we need to fail when there
    // are deprecations that get reported (i.e. not ignored or expected).
@@ -159,9 +173,11 @@ protected function runCommand(string $test_class_name, string $log_junit_file_pa
   *   The test run object.
   * @param string $test_class_name
   *   A fully qualified test class name.
   * @param int $status
   * @param int|null $status
   *   (optional) The exit status code of the PHPUnit process will be assigned
   *   to this variable.
   * @param bool $colors
   *   (optional) Whether to use colors in output. Defaults to FALSE.
   *
   * @return array
   *   The parsed results of PHPUnit's JUnit XML output, in the format of
@@ -169,11 +185,16 @@ protected function runCommand(string $test_class_name, string $log_junit_file_pa
   *
   * @internal
   */
  public function execute(TestRun $test_run, string $test_class_name, ?int &$status = NULL): array {
  public function execute(
    TestRun $test_run,
    string $test_class_name,
    ?int &$status = NULL,
    bool $colors = FALSE,
  ): array {
    $log_junit_file_path = $this->xmlLogFilePath($test_run->id());
    // Store output from our test run.
    $output = [];
    $this->runCommand($test_class_name, $log_junit_file_path, $status, $output);
    $this->runCommand($test_class_name, $log_junit_file_path, $status, $output, $colors);

    if ($status == TestStatus::PASS) {
      return JUnitConverter::xmlToRows($test_run->id(), $log_junit_file_path);
+4 −2
Original line number Diff line number Diff line
@@ -815,9 +815,11 @@ function simpletest_script_execute_batch(TestRunResultsStorageInterface $test_ru
 * Run a PHPUnit-based test.
 */
function simpletest_script_run_phpunit(TestRun $test_run, $class) {
  global $args;

  $runner = PhpUnitTestRunner::create(\Drupal::getContainer());
  $start = microtime(TRUE);
  $results = $runner->execute($test_run, $class, $status);
  $results = $runner->execute($test_run, $class, $status, $args['color']);
  $time = microtime(TRUE) - $start;

  $runner->processPhpUnitResults($test_run, $results);
@@ -1248,7 +1250,7 @@ function simpletest_script_format_result($result) {
  if ($args['non-html']) {
    $message = Html::decodeEntities($message);
  }
  $lines = explode("\n", wordwrap($message), 76);
  $lines = explode("\n", $message);
  foreach ($lines as $line) {
    echo "    $line\n";
  }