diff --git a/core/tests/Drupal/Tests/TestSuites/TestSuiteBaseTest.php b/core/tests/Drupal/Tests/TestSuites/TestSuiteBaseTest.php index bebb431..d545172 100644 --- a/core/tests/Drupal/Tests/TestSuites/TestSuiteBaseTest.php +++ b/core/tests/Drupal/Tests/TestSuites/TestSuiteBaseTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\TestSuites; +use Drupal\Tests\TestSuites\TestSuiteBase; use org\bovigo\vfs\vfsStream; /** @@ -33,6 +34,18 @@ protected function getFilesystem() { ], ], ], + 'modules' => [ + 'test_extension' => [ + 'test_extension.info.yml' => 'type: module', + 'tests' => [ + 'src' => [ + 'NotUnit' => [ + 'ContribNotUnitTest.php' => 'invokeArgs($stub, [vfsStream::url('root'), $suite_namespace]); // Determine if we loaded the expected test files. - $this->assertNotEmpty($stub->testFiles); - $this->assertEmpty(array_diff_assoc($expected_tests, $stub->testFiles)); + $this->assertSame($expected_tests, $stub->testFiles); + } + + public function provideContribTests() { + $filesystem = $this->getFilesystem(); + return [ + 'contrib-not-unit' => [ + $filesystem, + 'NotUnit', + [ + 'test_extension' => 'vfs://root/modules/test_extension', + ], + [ + 'Drupal\NotUnitTests\CoreNotUnitTest' => 'vfs://root/core/tests/Drupal/NotUnitTests/CoreNotUnitTest.php', + 'Drupal\Tests\test_extension\NotUnit\ContribNotUnitTest' => 'vfs://root/modules/test_extension/tests/src/NotUnit/ContribNotUnitTest.php', + ], + ], + ]; + } + + /** + * Tests for special case behavior of unit test suite namespaces in core. + * + * @covers ::addTestsBySuiteNamespace + * + * @dataProvider provideContribTests + */ + public function testAddTestsBySuiteNamespaceContrib($filesystem, $suite_namespace, $discovered_extension_tests, $expected_tests) { + // Set up the file system. + $vfs = vfsStream::setup('root'); + vfsStream::create($filesystem, $vfs); + + // Make a stub suite base to test. + $stub = new StubTestSuiteBase('test_me'); + + // Set up our mock extension directories. We have to stub out + // findExtensionDirectories() because we can't inject a vfsStream file + // system. + $stub->extensionDirectories = $discovered_extension_tests; + + // Access addTestsBySuiteNamespace(). + $ref_add_tests = new \ReflectionMethod($stub, 'addTestsBySuiteNamespace'); + $ref_add_tests->setAccessible(TRUE); + + // Invoke addTestsBySuiteNamespace(). + $ref_add_tests->invokeArgs($stub, [vfsStream::url('root'), $suite_namespace]); + + // Determine if we loaded the expected test files. + $this->assertSame($expected_tests, $stub->testFiles); } } @@ -108,6 +168,13 @@ class StubTestSuiteBase extends TestSuiteBase { public $testFiles = []; /** + * Extension directories. + * + * @var string[] + */ + public $extensionDirectories = []; + + /** * {@inheritdoc} */ protected function findExtensionDirectories($root) { @@ -116,7 +183,7 @@ protected function findExtensionDirectories($root) { // which uses \SplFileInfo->getRealPath(). getRealPath() resolves // stream-based paths to an empty string. See // https://github.com/mikey179/vfsStream/wiki/Known-Issues - return []; + return $this->extensionDirectories; } /**