3 namespace Drupal\Tests\simpletest\Unit;
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\Core\File\FileSystemInterface;
9 * Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly.
13 * @runTestsInSeparateProcesses
15 class SimpletestPhpunitRunCommandTest extends \PHPUnit_Framework_TestCase {
18 * Path to the app root.
22 protected static $root;
27 public static function setUpBeforeClass() {
28 parent::setUpBeforeClass();
29 // Figure out our app root.
30 self::$root = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
31 // Include the files we need for tests. The stub test we will run is
32 // SimpletestPhpunitRunCommandTestWillDie which is located in
33 // simpletest_phpunit_run_command_test.php.
34 include_once self::$root . '/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php';
35 // Since we're testing simpletest_run_phpunit_tests(), we need to include
37 include_once self::$root . '/core/modules/simpletest/simpletest.module';
43 protected function setUp() {
45 // Organize our mock container.
46 $container = new ContainerBuilder();
47 $container->set('app.root', self::$root);
48 $file_system = $this->prophesize(FileSystemInterface::class);
49 // The simpletest directory wrapper will always point to /tmp.
50 $file_system->realpath('public://simpletest')->willReturn(sys_get_temp_dir());
51 $container->set('file_system', $file_system->reveal());
52 \Drupal::setContainer($container);
56 * Data provider for testSimpletestPhpUnitRunCommand().
59 * Arrays of status codes and the label they're expected to have.
61 public function provideStatusCodes() {
67 // All status codes 3 and above should be labeled 'error'.
68 // @todo: The valid values here would be 3 to 127. But since the test
69 // touches the file system a lot, we only have 3, 4, and 127 for speed.
70 foreach ([3, 4, 127] as $status) {
71 $data[] = [$status, 'error'];
77 * Test the round trip for PHPUnit execution status codes.
79 * @covers ::simpletest_run_phpunit_tests
81 * @dataProvider provideStatusCodes
83 public function testSimpletestPhpUnitRunCommand($status, $label) {
84 $test_id = basename(tempnam(sys_get_temp_dir(), 'xxx'));
85 putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status);
86 $ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]);
87 $this->assertSame($ret[0]['status'], $label);
88 putenv('SimpletestPhpunitRunCommandTestWillDie');
89 unlink(simpletest_phpunit_xml_filepath($test_id));
95 protected function tearDown() {
96 // We unset the $base_url global, since the test code sets it as a
98 unset($GLOBALS['base_url']);