public function PhpUnitTestRunnerTest::testRunTestsError in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest::testRunTestsError()
Tests an error in the test running phase.
@covers ::runTests
File
- core/
tests/ Drupal/ Tests/ Core/ Test/ PhpUnitTestRunnerTest.php, line 22
Class
- PhpUnitTestRunnerTest
- @coversDefaultClass \Drupal\Core\Test\PhpUnitTestRunner @group Test
Namespace
Drupal\Tests\Core\TestCode
public function testRunTestsError() {
$test_id = 23;
$log_path = 'test_log_path';
// Create a mock runner.
$runner = $this
->getMockBuilder(PhpUnitTestRunner::class)
->disableOriginalConstructor()
->setMethods([
'xmlLogFilepath',
'runCommand',
])
->getMock();
// Set some expectations for xmlLogFilepath().
$runner
->expects($this
->once())
->method('xmlLogFilepath')
->willReturn($log_path);
// We mark a failure by having runCommand() deliver a serious status code.
$runner
->expects($this
->once())
->method('runCommand')
->willReturnCallback(function ($unescaped_test_classnames, $phpunit_file, &$status) {
$status = TestStatus::EXCEPTION;
});
// The runTests() method expects $status by reference, so we initialize it
// to some value we don't expect back.
$status = -1;
$results = $runner
->runTests($test_id, [
'SomeTest',
], $status);
// Make sure our status code made the round trip.
$this
->assertEquals(TestStatus::EXCEPTION, $status);
// A serious error in runCommand() should give us a fixed set of results.
$row = reset($results);
$fail_row = [
'test_id' => $test_id,
'test_class' => 'SomeTest',
'status' => TestStatus::label(TestStatus::EXCEPTION),
'message' => 'PHPUnit Test failed to complete; Error: ',
'message_group' => 'Other',
'function' => 'SomeTest',
'line' => '0',
'file' => $log_path,
];
$this
->assertEquals($fail_row, $row);
}