Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\simpletest\Unit; | |
4 | |
5 use Drupal\Core\DependencyInjection\ContainerBuilder; | |
6 use Drupal\Core\File\FileSystemInterface; | |
7 use PHPUnit\Framework\TestCase; | |
8 | |
9 /** | |
10 * Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly. | |
11 * | |
12 * We don't extend Drupal\Tests\UnitTestCase here because its $root property is | |
13 * not static and we need it to be static here. | |
14 * | |
15 * @group simpletest | |
16 * | |
17 * @runTestsInSeparateProcesses | |
18 */ | |
19 class SimpletestPhpunitRunCommandTest extends TestCase { | |
20 | |
21 /** | |
22 * Path to the app root. | |
23 * | |
24 * @var string | |
25 */ | |
26 protected static $root; | |
27 | |
28 /** | |
29 * {@inheritdoc} | |
30 */ | |
31 public static function setUpBeforeClass() { | |
32 parent::setUpBeforeClass(); | |
33 // Figure out our app root. | |
34 self::$root = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__)))))); | |
35 // Include the files we need for tests. The stub test we will run is | |
36 // SimpletestPhpunitRunCommandTestWillDie which is located in | |
37 // simpletest_phpunit_run_command_test.php. | |
38 include_once self::$root . '/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php'; | |
39 // Since we're testing simpletest_run_phpunit_tests(), we need to include | |
40 // simpletest.module. | |
41 include_once self::$root . '/core/modules/simpletest/simpletest.module'; | |
42 } | |
43 | |
44 /** | |
45 * {@inheritdoc} | |
46 */ | |
47 protected function setUp() { | |
48 parent::setUp(); | |
49 // Organize our mock container. | |
50 $container = new ContainerBuilder(); | |
51 $container->set('app.root', self::$root); | |
52 $file_system = $this->prophesize(FileSystemInterface::class); | |
53 // The simpletest directory wrapper will always point to /tmp. | |
54 $file_system->realpath('public://simpletest')->willReturn(sys_get_temp_dir()); | |
55 $container->set('file_system', $file_system->reveal()); | |
56 \Drupal::setContainer($container); | |
57 } | |
58 | |
59 /** | |
60 * Data provider for testSimpletestPhpUnitRunCommand(). | |
61 * | |
62 * @return array | |
63 * Arrays of status codes and the label they're expected to have. | |
64 */ | |
65 public function provideStatusCodes() { | |
66 $data = [ | |
67 [0, 'pass'], | |
68 [1, 'fail'], | |
69 [2, 'exception'], | |
70 ]; | |
71 // All status codes 3 and above should be labeled 'error'. | |
72 // @todo: The valid values here would be 3 to 127. But since the test | |
73 // touches the file system a lot, we only have 3, 4, and 127 for speed. | |
74 foreach ([3, 4, 127] as $status) { | |
75 $data[] = [$status, 'error']; | |
76 } | |
77 return $data; | |
78 } | |
79 | |
80 /** | |
81 * Test the round trip for PHPUnit execution status codes. | |
82 * | |
83 * @covers ::simpletest_run_phpunit_tests | |
84 * | |
85 * @dataProvider provideStatusCodes | |
86 */ | |
87 public function testSimpletestPhpUnitRunCommand($status, $label) { | |
88 $test_id = basename(tempnam(sys_get_temp_dir(), 'xxx')); | |
89 putenv('SimpletestPhpunitRunCommandTestWillDie=' . $status); | |
90 $ret = simpletest_run_phpunit_tests($test_id, [SimpletestPhpunitRunCommandTestWillDie::class]); | |
91 $this->assertSame($ret[0]['status'], $label); | |
92 putenv('SimpletestPhpunitRunCommandTestWillDie'); | |
93 unlink(simpletest_phpunit_xml_filepath($test_id)); | |
94 } | |
95 | |
96 /** | |
97 * {@inheritdoc} | |
98 */ | |
99 protected function tearDown() { | |
100 // We unset the $base_url global, since the test code sets it as a | |
101 // side-effect. | |
102 unset($GLOBALS['base_url']); | |
103 parent::tearDown(); | |
104 } | |
105 | |
106 } |