Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\TestSuites;
|
Chris@0
|
4
|
Chris@0
|
5 use org\bovigo\vfs\vfsStream;
|
Chris@0
|
6 use PHPUnit\Framework\TestCase;
|
Chris@0
|
7
|
Chris@0
|
8 // The test suite class is not part of the autoloader, we need to include it
|
Chris@0
|
9 // manually.
|
Chris@0
|
10 require_once __DIR__ . '/../../../TestSuites/TestSuiteBase.php';
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * @coversDefaultClass \Drupal\Tests\TestSuites\TestSuiteBase
|
Chris@0
|
14 *
|
Chris@0
|
15 * @group TestSuite
|
Chris@0
|
16 */
|
Chris@0
|
17 class TestSuiteBaseTest extends TestCase {
|
Chris@0
|
18
|
Chris@0
|
19 /**
|
Chris@0
|
20 * Helper method to set up the file system.
|
Chris@0
|
21 *
|
Chris@0
|
22 * @return array[]
|
Chris@0
|
23 * A Drupal filesystem suitable for use with vfsStream.
|
Chris@0
|
24 */
|
Chris@0
|
25 protected function getFilesystem() {
|
Chris@0
|
26 return [
|
Chris@0
|
27 'core' => [
|
Chris@0
|
28 'modules' => [],
|
Chris@0
|
29 'profiles' => [],
|
Chris@0
|
30 'tests' => [
|
Chris@0
|
31 'Drupal' => [
|
Chris@0
|
32 'NotUnitTests' => [
|
Chris@0
|
33 'CoreNotUnitTest.php' => '<?php',
|
Chris@0
|
34 ],
|
Chris@0
|
35 'Tests' => [
|
Chris@0
|
36 'CoreUnitTest.php' => '<?php',
|
Chris@0
|
37 ],
|
Chris@0
|
38 ],
|
Chris@0
|
39 ],
|
Chris@0
|
40 ],
|
Chris@0
|
41 ];
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 /**
|
Chris@0
|
45 * @return array[]
|
Chris@0
|
46 * Test data for testAddTestsBySuiteNamespaceCore(). An array of arrays:
|
Chris@0
|
47 * - A filesystem array for vfsStream.
|
Chris@0
|
48 * - The sub-namespace of the test suite.
|
Chris@0
|
49 * - The array of tests expected to be discovered.
|
Chris@0
|
50 */
|
Chris@0
|
51 public function provideCoreTests() {
|
Chris@0
|
52 $filesystem = $this->getFilesystem();
|
Chris@0
|
53 return [
|
Chris@0
|
54 'unit-tests' => [
|
Chris@0
|
55 $filesystem,
|
Chris@0
|
56 'Unit',
|
Chris@0
|
57 [
|
Chris@0
|
58 'Drupal\Tests\CoreUnitTest' => 'vfs://root/core/tests/Drupal/Tests/CoreUnitTest.php',
|
Chris@0
|
59 ],
|
Chris@0
|
60 ],
|
Chris@0
|
61 'not-unit-tests' => [
|
Chris@0
|
62 $filesystem,
|
Chris@0
|
63 'NotUnit',
|
Chris@0
|
64 [
|
Chris@0
|
65 'Drupal\NotUnitTests\CoreNotUnitTest' => 'vfs://root/core/tests/Drupal/NotUnitTests/CoreNotUnitTest.php',
|
Chris@0
|
66 ],
|
Chris@0
|
67 ],
|
Chris@0
|
68 ];
|
Chris@0
|
69 }
|
Chris@0
|
70
|
Chris@0
|
71 /**
|
Chris@0
|
72 * Tests for special case behavior of unit test suite namespaces in core.
|
Chris@0
|
73 *
|
Chris@0
|
74 * @covers ::addTestsBySuiteNamespace
|
Chris@0
|
75 *
|
Chris@0
|
76 * @dataProvider provideCoreTests
|
Chris@0
|
77 */
|
Chris@0
|
78 public function testAddTestsBySuiteNamespaceCore($filesystem, $suite_namespace, $expected_tests) {
|
Chris@0
|
79 // Set up the file system.
|
Chris@0
|
80 $vfs = vfsStream::setup('root');
|
Chris@0
|
81 vfsStream::create($filesystem, $vfs);
|
Chris@0
|
82
|
Chris@0
|
83 // Make a stub suite base to test.
|
Chris@0
|
84 $stub = new StubTestSuiteBase('test_me');
|
Chris@0
|
85
|
Chris@0
|
86 // Access addTestsBySuiteNamespace().
|
Chris@0
|
87 $ref_add_tests = new \ReflectionMethod($stub, 'addTestsBySuiteNamespace');
|
Chris@0
|
88 $ref_add_tests->setAccessible(TRUE);
|
Chris@0
|
89
|
Chris@0
|
90 // Invoke addTestsBySuiteNamespace().
|
Chris@0
|
91 $ref_add_tests->invokeArgs($stub, [vfsStream::url('root'), $suite_namespace]);
|
Chris@0
|
92
|
Chris@0
|
93 // Determine if we loaded the expected test files.
|
Chris@0
|
94 $this->assertNotEmpty($stub->testFiles);
|
Chris@0
|
95 $this->assertEmpty(array_diff_assoc($expected_tests, $stub->testFiles));
|
Chris@0
|
96 }
|
Chris@0
|
97
|
Chris@0
|
98 /**
|
Chris@0
|
99 * Tests the assumption that local time is in 'Australia/Sydney'.
|
Chris@0
|
100 */
|
Chris@0
|
101 public function testLocalTimeZone() {
|
Chris@0
|
102 // The 'Australia/Sydney' time zone is set in core/tests/bootstrap.php
|
Chris@0
|
103 $this->assertEquals('Australia/Sydney', date_default_timezone_get());
|
Chris@0
|
104 }
|
Chris@0
|
105
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 /**
|
Chris@0
|
109 * Stub subclass of TestSuiteBase.
|
Chris@0
|
110 *
|
Chris@0
|
111 * We use this class to alter the behavior of TestSuiteBase so it can be
|
Chris@0
|
112 * testable.
|
Chris@0
|
113 */
|
Chris@0
|
114 class StubTestSuiteBase extends TestSuiteBase {
|
Chris@0
|
115
|
Chris@0
|
116 /**
|
Chris@0
|
117 * Test files discovered by addTestsBySuiteNamespace().
|
Chris@0
|
118 *
|
Chris@0
|
119 * @var string[]
|
Chris@0
|
120 */
|
Chris@0
|
121 public $testFiles = [];
|
Chris@0
|
122
|
Chris@0
|
123 /**
|
Chris@0
|
124 * {@inheritdoc}
|
Chris@0
|
125 */
|
Chris@0
|
126 protected function findExtensionDirectories($root) {
|
Chris@0
|
127 // We have to stub findExtensionDirectories() because we can't inject a
|
Chris@0
|
128 // vfsStream filesystem into drupal_phpunit_find_extension_directories(),
|
Chris@0
|
129 // which uses \SplFileInfo->getRealPath(). getRealPath() resolves
|
Chris@0
|
130 // stream-based paths to an empty string. See
|
Chris@0
|
131 // https://github.com/mikey179/vfsStream/wiki/Known-Issues
|
Chris@0
|
132 return [];
|
Chris@0
|
133 }
|
Chris@0
|
134
|
Chris@0
|
135 /**
|
Chris@0
|
136 * {@inheritdoc}
|
Chris@0
|
137 */
|
Chris@0
|
138 public function addTestFiles($filenames) {
|
Chris@0
|
139 // We stub addTestFiles() because the parent implementation can't deal with
|
Chris@0
|
140 // vfsStream-based filesystems due to an error in
|
Chris@0
|
141 // stream_resolve_include_path(). See
|
Chris@0
|
142 // https://github.com/mikey179/vfsStream/issues/5 Here we just store the
|
Chris@0
|
143 // test file being added in $this->testFiles.
|
Chris@0
|
144 $this->testFiles = array_merge($this->testFiles, $filenames);
|
Chris@0
|
145 }
|
Chris@0
|
146
|
Chris@0
|
147 }
|