diff --git a/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php b/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php index 445c225e8b..5a38c89832 100644 --- a/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php @@ -6,17 +6,22 @@ use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; -// Require the base class. We do this to avoid making the test suite classes -// autoloadable. -require_once __DIR__ . '/../../TestSuites/TestSuiteBase.php'; - /** * @coversDefaultClass \Drupal\TestSuites\TestSuiteBase * + * @runTestsInSeparateProcesses + * * @group TestSuite */ class TestSuiteBaseTest extends TestCase { + protected function setUp() { + parent::setUp(); + // Require the base class. We do this to avoid making the test suite classes + // autoloadable. + require_once __DIR__ . '/../../../TestSuites/TestSuiteBase.php'; + } + /** * Helper method to set up the file system. * @@ -88,18 +93,43 @@ public function testAddTestsBySuiteNamespaceCore($filesystem, $suite_namespace, $vfs = vfsStream::setup('root'); vfsStream::create($filesystem, $vfs); - // Make a stub suite base to test. - $stub = new StubTestSuiteBase('test_me'); + $mock = $this->getMockBuilder(TestSuiteBase::class) + ->setConstructorArgs(['test_me']) + ->setMethods(['findExtensionDirectories', 'addTestFiles']) + ->getMockForAbstractClass(); + + // The test files discovered by our mock. + $test_files = []; + + // We have to stub findExtensionDirectories() because we can't inject a + // vfsStream filesystem into drupal_phpunit_find_extension_directories(), + // which uses \SplFileInfo->getRealPath(). getRealPath() resolves + // stream-based paths to an empty string. See + // https://github.com/mikey179/vfsStream/wiki/Known-Issues + $mock->expects($this->once()) + ->method('findExtensionDirectories') + ->willReturn([]); + // We mock addTestFiles() because the parent implementation can't deal with + // vfsStream-based filesystems due to an error in + // stream_resolve_include_path(). See + // https://github.com/mikey179/vfsStream/issues/5 Here we just store the + // test file being added in $test_files. + $mock->expects($this->once()) + ->method('addTestFiles') + ->willReturnCallback( + function ($filenames) use (&$test_files) { + $test_files = array_merge($test_files, $filenames); + }); // Access addTestsBySuiteNamespace(). - $ref_add_tests = new \ReflectionMethod($stub, 'addTestsBySuiteNamespace'); + $ref_add_tests = new \ReflectionMethod($mock, 'addTestsBySuiteNamespace'); $ref_add_tests->setAccessible(TRUE); // Invoke addTestsBySuiteNamespace(). - $ref_add_tests->invokeArgs($stub, [vfsStream::url('root'), $suite_namespace]); + $ref_add_tests->invokeArgs($mock, [vfsStream::url('root'), $suite_namespace]); // Determine if we loaded the expected test files. - $this->assertEquals($expected_tests, $stub->testFiles); + $this->assertEquals($expected_tests, $test_files); } /** @@ -111,44 +141,3 @@ public function testLocalTimeZone() { } } - -/** - * Stub subclass of TestSuiteBase. - * - * We use this class to alter the behavior of TestSuiteBase so it can be - * testable. - */ -class StubTestSuiteBase extends TestSuiteBase { - - /** - * Test files discovered by addTestsBySuiteNamespace(). - * - * @var string[] - */ - public $testFiles = []; - - /** - * {@inheritdoc} - */ - protected function findExtensionDirectories($root) { - // We have to stub findExtensionDirectories() because we can't inject a - // vfsStream filesystem into drupal_phpunit_find_extension_directories(), - // which uses \SplFileInfo->getRealPath(). getRealPath() resolves - // stream-based paths to an empty string. See - // https://github.com/mikey179/vfsStream/wiki/Known-Issues - return []; - } - - /** - * {@inheritdoc} - */ - public function addTestFiles($filenames) { - // We stub addTestFiles() because the parent implementation can't deal with - // vfsStream-based filesystems due to an error in - // stream_resolve_include_path(). See - // https://github.com/mikey179/vfsStream/issues/5 Here we just store the - // test file being added in $this->testFiles. - $this->testFiles = array_merge($this->testFiles, $filenames); - } - -}