diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php index 132694607c282589767a658ffb961ef9b8821985..219106e80c22a7b5f0a9adcad1c64fb98fe40fc1 100644 --- a/core/modules/simpletest/src/TestDiscovery.php +++ b/core/modules/simpletest/src/TestDiscovery.php @@ -325,7 +325,7 @@ public static function scanDirectory($namespace_prefix, $path) { * If the class does not have a @group annotation. */ public static function getTestInfo($classname, $doc_comment = NULL) { - if (!$doc_comment) { + if ($doc_comment === NULL) { $reflection = new \ReflectionClass($classname); $doc_comment = $reflection->getDocComment(); } diff --git a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php b/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php index 625297e4397a4518079602040fbf7121dd60b98b..8b00bb40b38ad9115729d1bd52a8eb40f46a10a3 100644 --- a/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php +++ b/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php @@ -385,6 +385,21 @@ public function providerTestGetPhpunitTestSuite() { return $data; } + /** + * Ensure that classes are not reflected when the docblock is empty. + * + * @covers ::getTestInfo + */ + public function testGetTestInfoEmptyDocblock() { + // If getTestInfo() performed reflection, it won't be able to find the + // class we asked it to analyze, so it will throw a ReflectionException. + // We want to make sure it didn't do that, because we already did some + // analysis and already have an empty docblock. getTestInfo() will throw + // MissingGroupException because the annotation is empty. + $this->setExpectedException(MissingGroupException::class); + TestDiscovery::getTestInfo('Drupal\Tests\simpletest\ThisTestDoesNotExistTest', ''); + } + } class TestTestDiscovery extends TestDiscovery {