class PhpUnitTestRunnerTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest
- 10 core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest
- 9 core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest
- 8.9.x core/tests/Drupal/Tests/Core/Test/PhpUnitTestRunnerTest.php \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest
Tests Drupal\Core\Test\PhpUnitTestRunner.
Attributes
#[CoversClass(PhpUnitTestRunner::class)]
#[Group('Test')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Test\PhpUnitTestRunnerTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of PhpUnitTestRunnerTest
See also
Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Test/ PhpUnitTestRunnerTest.php, line 23
Namespace
Drupal\Tests\Core\TestView source
class PhpUnitTestRunnerTest extends UnitTestCase {
/**
* Tests an error in the test running phase.
*/
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);
}
/**
* Tests php unit command.
*/
public function testPhpUnitCommand() : void {
$runner = new PhpUnitTestRunner($this->root, sys_get_temp_dir());
$this->assertMatchesRegularExpression('/phpunit/', $runner->phpUnitCommand());
}
/**
* Tests xml log file path.
*/
public function testXmlLogFilePath() : void {
$runner = new PhpUnitTestRunner($this->root, sys_get_temp_dir());
$this->assertStringEndsWith('phpunit-23.xml', $runner->xmlLogFilePath(23));
}
public static function providerTestSummarizeResults() : array {
return [
[
[
[
'test_class' => static::class,
'status' => 'pass',
'time' => 0.010001,
],
],
'#pass',
],
[
[
[
'test_class' => static::class,
'status' => 'fail',
'time' => 0.010002,
],
],
'#fail',
],
[
[
[
'test_class' => static::class,
'status' => 'exception',
'time' => 0.010003,
],
],
'#exception',
],
[
[
[
'test_class' => static::class,
'status' => 'debug',
'time' => 0.010004,
],
],
'#debug',
],
];
}
/**
* Tests summarize results.
*/
public function testSummarizeResults($results, $has_status) : void {
$runner = new PhpUnitTestRunner($this->root, sys_get_temp_dir());
$summary = $runner->summarizeResults($results);
$this->assertArrayHasKey(static::class, $summary);
$this->assertEquals(1, $summary[static::class][$has_status]);
foreach (array_diff([
'#pass',
'#fail',
'#exception',
'#debug',
], [
$has_status,
]) as $should_be_zero) {
$this->assertSame(0, $summary[static::class][$should_be_zero]);
}
}
}
Members
| Title Sort descending | Deprecated | Modifiers | Object type | Summary |
|---|---|---|---|---|
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | |
| ExpectDeprecationTrait::expectDeprecation | Deprecated | public | function | Adds an expected deprecation. |
| ExpectDeprecationTrait::regularExpressionForFormatDescription | private | function | ||
| PhpUnitTestRunnerTest::providerTestSummarizeResults | public static | function | ||
| PhpUnitTestRunnerTest::testPhpUnitCommand | public | function | Tests php unit command. | |
| PhpUnitTestRunnerTest::testRunTestsError | public | function | Tests an error in the test running phase. | |
| PhpUnitTestRunnerTest::testSummarizeResults | public | function | Tests summarize results. | |
| PhpUnitTestRunnerTest::testXmlLogFilePath | public | function | Tests xml log file path. | |
| RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
| RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
| RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
| RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
| UnitTestCase::$root | protected | property | The app root. | |
| UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
| UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setUp | protected | function | ||
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.