diff --git a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php index 5178343..5a37984 100644 --- a/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php +++ b/core/lib/Drupal/Core/Test/PhpUnitTestRunner.php @@ -134,7 +134,7 @@ public function phpUnitCommand() { * @return string * The results as returned by exec(). */ - function runCommand(array $unescaped_test_classnames, $phpunit_file, &$status = NULL, &$output = NULL) { + public function runCommand(array $unescaped_test_classnames, $phpunit_file, &$status = NULL, &$output = NULL) { global $base_url; // Setup an environment variable containing the database connection so that // functional tests can connect to the database. @@ -144,6 +144,7 @@ function runCommand(array $unescaped_test_classnames, $phpunit_file, &$status = // This allows functional tests to browse the site under test. When running // tests via CLI, core/phpunit.xml.dist or core/scripts/run-tests.sh can set // this variable. + // @todo: Convert $base_url to an injected property. if ($base_url) { putenv('SIMPLETEST_BASE_URL=' . $base_url); } @@ -178,9 +179,9 @@ function runCommand(array $unescaped_test_classnames, $phpunit_file, &$status = $old_cwd = getcwd(); chdir($this->appRoot . '/core'); - // exec in a subshell so that the environment is isolated when running tests - // via the simpletest UI. - $ret = exec(join($command, " "), $output, $status); + // Call exec() in a subshell so that the environment is isolated when + // running tests via the simpletest UI. + $ret = exec(implode(" ", $command), $output, $status); chdir($old_cwd); putenv('SIMPLETEST_DB='); @@ -193,9 +194,9 @@ function runCommand(array $unescaped_test_classnames, $phpunit_file, &$status = /** * Executes PHPUnit tests and returns the results of the run. * - * @param $test_id + * @param int $test_id * The current test ID. - * @param $unescaped_test_classnames + * @param string[] $unescaped_test_classnames * An array of test class names, including full namespaces, to be passed as * a regular expression to PHPUnit's --filter option. * @param int $status @@ -209,7 +210,7 @@ function runCommand(array $unescaped_test_classnames, $phpunit_file, &$status = * @deprecated in Drupal 8.3.x, will be removed before 9.0.0. Use * Drupal\Core\Test\PhpUnitTestRunner::runTests(). */ - function runTests($test_id, array $unescaped_test_classnames, &$status = NULL) { + public function runTests($test_id, array $unescaped_test_classnames, &$status = NULL) { $phpunit_file = $this->xmlLogFilepath($test_id); $this->runCommand($unescaped_test_classnames, $phpunit_file, $status, $output); $rows = JUnitConverter::xmlToRows($test_id, $phpunit_file); diff --git a/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php b/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php index d283a6d..9c542cc 100644 --- a/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php +++ b/core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php @@ -19,6 +19,7 @@ class PhpUnitTestRunnerTest extends \PHPUnit_Framework_TestCase { */ public function testRunTestsError() { $log_path = 'test_log_path'; + $test_id = 23; // Create a mock runner. $runner = $this->getMockBuilder(PhpUnitTestRunner::class) @@ -35,15 +36,16 @@ public function testRunTestsError() { $runner->expects($this->once()) ->method('runCommand') ->willReturnCallback( - function ($unescaped_test_classnames, $phpunit_file, &$status) { + function ($unescaped_test_classnames, $phpunit_file, &$status, &$output) { $status = 2; + $output = ['This is output from the test run explaining what happened.']; } ); // The runTests() method expects $status by reference, so we initialize it // to some value we don't expect back. $status = -1; - $results = $runner->runTests(23, ['SomeTest'], $status); + $results = $runner->runTests($test_id, ['SomeTest'], $status); // Make sure our status code made the round trip. $this->assertEquals(2, $status); @@ -51,10 +53,10 @@ function ($unescaped_test_classnames, $phpunit_file, &$status) { // A serious error in runCommand() should give us a fixed set of results. $row = reset($results); $fail_row = [ - 'test_id' => '1', + 'test_id' => $test_id, 'test_class' => 'SomeTest', 'status' => 'fail', - 'message' => 'PHPunit Test failed to complete', + 'message' => 'PHPunit Test failed to complete; Error: This is output from the test run explaining what happened.', 'message_group' => 'Other', 'function' => 'SomeTest', 'line' => '0',