diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 665b8baaba..f49a8c42bc 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -205,9 +205,9 @@ function simpletest_run_tests($test_list) { * The parsed results of PHPUnit's JUnit XML output, in the format of * {simpletest}'s schema. */ -function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames, &$status = NULL) { +function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames, &$status = NULL, $environment_variables = []) { $phpunit_file = simpletest_phpunit_xml_filepath($test_id); - simpletest_phpunit_run_command($unescaped_test_classnames, $phpunit_file, $status, $output); + simpletest_phpunit_run_command($unescaped_test_classnames, $phpunit_file, $status, $output, $environment_variables); $rows = []; if ($status == TestStatus::PASS) { @@ -219,7 +219,7 @@ function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames 'test_id' => $test_id, 'test_class' => implode(",", $unescaped_test_classnames), 'status' => TestStatus::label($status), - 'message' => 'PHPunit Test failed to complete; Error: ' . $output, + 'message' => 'PHPunit Test failed to complete; Error: ' . implode("\n", $output), 'message_group' => 'Other', 'function' => implode(",", $unescaped_test_classnames), 'line' => '0', @@ -356,14 +356,14 @@ function simpletest_phpunit_configuration_filepath() { * @return string * The results as returned by exec(). */ -function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL, &$output = NULL) { +function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL, &$output = NULL, $environment_variables = []) { global $base_url; // Setup an environment variable containing the database connection so that // functional tests can connect to the database. - $process_environment_variables = [ + $process_environment_variables = array_merge($environment_variables, [ 'SIMPLETEST_DB' => Database::getConnectionInfoAsUrl(), 'SIMPLETEST_JUNIT_FILE' => $phpunit_file, - ]; + ]); // Setup an environment variable containing the base URL, if it is available. // This allows functional tests to browse the site under test. When running @@ -377,6 +377,8 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun $command = [ $phpunit_bin, + '--printer', + SimpletestUiPrinter::class, ]; // Optimized for running a single test. @@ -401,7 +403,7 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun $process->inheritEnvironmentVariables(); $process->setTimeout(NULL); $process->run(); - $output = $process->getOutput(); + $output = explode("\n", $process->getOutput()); $status = $process->getExitCode(); return ''; diff --git a/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php index 30617b9560..7fda979f6f 100644 --- a/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php +++ b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php @@ -54,6 +54,8 @@ protected function setUp() { $file_system = $this->prophesize(FileSystemInterface::class); // The simpletest directory wrapper will always point to /tmp. $file_system->realpath('public://simpletest')->willReturn(sys_get_temp_dir()); + // The simpletest directory wrapper preparation will always be true. + $file_system->prepareDirectory(sys_get_temp_dir(), FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)->willReturn(TRUE); $container->set('file_system', $file_system->reveal()); \Drupal::setContainer($container); } @@ -100,10 +102,8 @@ public function testSimpletestPhpUnitRunCommand($status, $label) { ] ); $test_id = basename(tempnam(sys_get_temp_dir(), 'xxx')); - putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status); - $ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]); - $this->assertSame($ret[0]['status'], $label); - putenv('SimpletestPhpunitRunCommandTestWillDie'); + $ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class], $status, ['SimpletestPhpunitRunCommandTestWillDie' => $status]); + $this->assertSame($label, $ret[0]['status']); unlink(simpletest_phpunit_xml_filepath($test_id)); }