3 namespace Drupal\Tests\TestSuites;
5 use org\bovigo\vfs\vfsStream;
7 // The test suite class is not part of the autoloader, we need to include it
9 require_once __DIR__ . '/../../../TestSuites/TestSuiteBase.php';
12 * @coversDefaultClass \Drupal\Tests\TestSuites\TestSuiteBase
16 class TestSuiteBaseTest extends \PHPUnit_Framework_TestCase {
19 * Helper method to set up the file system.
22 * A Drupal filesystem suitable for use with vfsStream.
24 protected function getFilesystem() {
32 'CoreNotUnitTest.php' => '<?php',
35 'CoreUnitTest.php' => '<?php',
45 * Test data for testAddTestsBySuiteNamespaceCore(). An array of arrays:
46 * - A filesystem array for vfsStream.
47 * - The sub-namespace of the test suite.
48 * - The array of tests expected to be discovered.
50 public function provideCoreTests() {
51 $filesystem = $this->getFilesystem();
57 'Drupal\Tests\CoreUnitTest' => 'vfs://root/core/tests/Drupal/Tests/CoreUnitTest.php',
64 'Drupal\NotUnitTests\CoreNotUnitTest' => 'vfs://root/core/tests/Drupal/NotUnitTests/CoreNotUnitTest.php',
71 * Tests for special case behavior of unit test suite namespaces in core.
73 * @covers ::addTestsBySuiteNamespace
75 * @dataProvider provideCoreTests
77 public function testAddTestsBySuiteNamespaceCore($filesystem, $suite_namespace, $expected_tests) {
78 // Set up the file system.
79 $vfs = vfsStream::setup('root');
80 vfsStream::create($filesystem, $vfs);
82 // Make a stub suite base to test.
83 $stub = new StubTestSuiteBase('test_me');
85 // Access addTestsBySuiteNamespace().
86 $ref_add_tests = new \ReflectionMethod($stub, 'addTestsBySuiteNamespace');
87 $ref_add_tests->setAccessible(TRUE);
89 // Invoke addTestsBySuiteNamespace().
90 $ref_add_tests->invokeArgs($stub, [vfsStream::url('root'), $suite_namespace]);
92 // Determine if we loaded the expected test files.
93 $this->assertNotEmpty($stub->testFiles);
94 $this->assertEmpty(array_diff_assoc($expected_tests, $stub->testFiles));
100 * Stub subclass of TestSuiteBase.
102 * We use this class to alter the behavior of TestSuiteBase so it can be
105 class StubTestSuiteBase extends TestSuiteBase {
108 * Test files discovered by addTestsBySuiteNamespace().
112 public $testFiles = [];
117 protected function findExtensionDirectories($root) {
118 // We have to stub findExtensionDirectories() because we can't inject a
119 // vfsStream filesystem into drupal_phpunit_find_extension_directories(),
120 // which uses \SplFileInfo->getRealPath(). getRealPath() resolves
121 // stream-based paths to an empty string. See
122 // https://github.com/mikey179/vfsStream/wiki/Known-Issues
129 public function addTestFiles($filenames) {
130 // We stub addTestFiles() because the parent implementation can't deal with
131 // vfsStream-based filesystems due to an error in
132 // stream_resolve_include_path(). See
133 // https://github.com/mikey179/vfsStream/issues/5 Here we just store the
134 // test file being added in $this->testFiles.
135 $this->testFiles = array_merge($this->testFiles, $filenames);