function PhpUnitTestRunnerTest::testRunTestsError
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest::testRunTestsError()
- 10 core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest::testRunTestsError()
- 9 core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest::testRunTestsError()
- 8.9.x core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest::testRunTestsError()
Tests an error in the test running phase.
File
-
core/
tests/ Drupal/ Tests/ Core/ Test/ PhpUnitTestRunnerTest.php, line 30
Class
Namespace
Drupal\Tests\Core\TestCode
public function testRunTestsError() : void {
$test_id = 23;
$log_path = 'test_log_path';
// Create a mock test run storage.
$storage = $this->getMockBuilder(SimpletestTestRunResultsStorage::class)
->setConstructorArgs([
$this->createStub(Connection::class),
])
->onlyMethods([
'createNew',
])
->getMock();
$storage->expects($this->once())
->method('createNew')
->willReturn($test_id);
// Create a mock runner.
$runner = $this->getMockBuilder(PhpUnitTestRunner::class)
->setConstructorArgs([
'',
'',
])
->onlyMethods([
'xmlLogFilepath',
'processPhpUnitResults',
])
->getMock();
$runner->expects($this->once())
->method('xmlLogFilepath')
->willReturn($log_path);
$runner->expects($this->once())
->method('processPhpUnitResults');
// Create a mock process.
$process = $this->createMock(Process::class);
$process->expects($this->once())
->method('isTerminated')
->willReturn(TRUE);
$process->expects($this->once())
->method('getOutput')
->willReturn('A most serious error occurred.');
$process->expects($this->once())
->method('getExitCode')
->willReturn(TestStatus::SYSTEM);
// The execute() method expects $status by reference, so we initialize it
// to some value we don't expect back.
$test_run = TestRun::createNew($storage);
$test_run->start(microtime(TRUE));
$test_run->end(microtime(TRUE));
$process_outcome = $runner->processPhpUnitOnSingleTestClassOutcome($process, $test_run, 'SomeTest');
// Make sure our status code made the round trip.
$this->assertEquals(TestStatus::SYSTEM, $process_outcome['status']);
// A serious error in runCommand() should give us a fixed set of results.
$row = reset($process_outcome['phpunit_results']);
unset($row['time']);
$fail_row = [
'test_id' => $test_id,
'test_class' => 'SomeTest',
'status' => TestStatus::label(TestStatus::SYSTEM),
'message' => 'A most serious error occurred.',
'message_group' => 'Other',
'function' => '*** Process execution output ***',
'line' => '0',
'file' => $log_path,
'exit_code' => 3,
];
$this->assertEquals($fail_row, $row);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.