From 63329e4b7e810cb2ad7dfe83746928330b7ba5f5 Mon Sep 17 00:00:00 2001 From: Alies Lapatsin <5278175+alies-dev@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:21:46 +0100 Subject: [PATCH 1/3] Cover the methods the per-class method loops must keep checking #289 Trait aliases with test names, #[Test] and @test on methods with other names in a trait and in a parent (also when only the subclass file is analysed), a hook tag and a malformed tag on trait methods, and every docblock tag PHPUnit 11 reads. --- tests/acceptance/AnnotationParsing.feature | 23 ++++ tests/acceptance/DataProviders.feature | 130 +++++++++++++++++++ tests/acceptance/DeadCode.feature | 41 ++++++ tests/acceptance/DocblockMetadata.feature | 139 +++++++++++++++++++++ 4 files changed, 333 insertions(+) diff --git a/tests/acceptance/AnnotationParsing.feature b/tests/acceptance/AnnotationParsing.feature index 1b0099f..1a8b181 100644 --- a/tests/acceptance/AnnotationParsing.feature +++ b/tests/acceptance/AnnotationParsing.feature @@ -648,3 +648,26 @@ final class MyTestCase extends TestCase | Type | Message | Line | | InvalidPhpUnitAnnotation | Annotation "@covers" has no value | 14 | And I see no other errors + + Scenario: Malformed annotation on a trait method that is not a test is reported + Given I have the following code + """ + trait HelperTrait + { + /** + * @group + */ + public function helper(): void { + } + } + + final class MyTestCase extends TestCase + { + use HelperTrait; + } + """ + When I run Psalm + Then I see these errors + | Type | Message | Line | + | InvalidPhpUnitAnnotation | Annotation "@group" has no value | 8 | + And I see no other errors diff --git a/tests/acceptance/DataProviders.feature b/tests/acceptance/DataProviders.feature index 0c8134c..2a5b3f2 100644 --- a/tests/acceptance/DataProviders.feature +++ b/tests/acceptance/DataProviders.feature @@ -1400,3 +1400,133 @@ Feature: Data providers """ When I run Psalm Then I see no errors + + Scenario: A trait test imported as protected is checked under the public name it is also imported with + Given I have the following code + """ + use PHPUnit\Framework\Attributes\DataProvider; + use PHPUnit\Framework\Attributes\Test; + + trait HelperTrait + { + #[Test] + #[DataProvider('provide')] + public function check(int $int): void { + $this->assertSame(1, $int); + } + } + + final class MyTestCase extends TestCase + { + use HelperTrait { + check as protected; + check as public verify; + } + + /** + * @return iterable + * @psalm-pure + */ + public static function provide(): iterable { + yield ['a']; + } + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidArgument | Argument 1 of NS\HelperTrait::check expects int, string provided by NS\MyTestCase::provide():(iterable[pure]) | + And I see no other errors + + Scenario: Invalid implementation of an abstract data provider of an inherited @test method is reported + Given I have the following code + """ + abstract class BaseTestCase extends TestCase { + /** + * @return iterable> + * @psalm-pure + */ + abstract public function provide(); + + /** + * @test + * @dataProvider provide + */ + public function check(int $int): void { + $this->assertSame(1, $int); + } + } + + final class MyTestCase extends BaseTestCase { + /** + * @return iterable> + * @psalm-pure + */ + #[\Override] + public function provide() { + yield [1]; + } + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | InvalidDataProvider | Data provider method NS\MyTestCase::provide must be static | + And I see no other errors + + Scenario: Invalid implementation of an abstract data provider of an inherited #[Test] method is reported when only the file of the subclass is analysed + Given I have the following code in "BaseTestCase.php" + """ + > + * @psalm-pure + */ + abstract public function provide(); + + #[Test] + #[DataProvider('provide')] + public function check(int $int): void { + $this->assertSame(1, $int); + } + } + """ + And I have the following code in "test.php" + """ + > + * @psalm-pure + */ + #[\Override] + public function provide() { + yield [1]; + } + } + """ + And I have the following code in "autoload.php" + """ + assertTrue(true); + } + } + + final class MyTestCase extends TestCase { + use Checks { + check as testCheck; + } + } + """ + When I run Psalm with dead code detection + Then I see no errors + + Scenario: A hook docblock tag of a method of a trait used by the test case is used by PHPUnit 11 + Given I have the following code + """ + trait Prepares { + /** + * @before + */ + public function prepare(): void { + $this->assertTrue(true); + } + } + + final class MyTestCase extends TestCase { + use Prepares; + + public function testSomething(): void { + $this->assertTrue(true); + } + } + """ + When I run Psalm with dead code detection + Then I see no errors diff --git a/tests/acceptance/DocblockMetadata.feature b/tests/acceptance/DocblockMetadata.feature index 9352bfd..09c1eed 100644 --- a/tests/acceptance/DocblockMetadata.feature +++ b/tests/acceptance/DocblockMetadata.feature @@ -563,3 +563,142 @@ Feature: Docblock metadata ignored by PHPUnit 12 and newer | Type | Message | Line | | IgnoredDocblockMetadata | PHPUnit 12 ignores the @group docblock tag, use #[Group] instead | 7 | And I see no other errors + + Scenario: PHPUnit 12 reports each docblock tag PHPUnit 11 reads + Given PHPUnit identifies as version "12.5.43" + And I have the following code + """ + final class MyTestCase extends TestCase { + /** @after x */ + public function method1(): void {} + + /** @afterClass x */ + public function method2(): void {} + + /** @backupGlobals x */ + public function method3(): void {} + + /** @backupStaticAttributes x */ + public function method4(): void {} + + /** @backupStaticProperties x */ + public function method5(): void {} + + /** @before x */ + public function method6(): void {} + + /** @beforeClass x */ + public function method7(): void {} + + /** @covers x */ + public function method8(): void {} + + /** @coversDefaultClass x */ + public function method9(): void {} + + /** @coversNothing x */ + public function method10(): void {} + + /** @dataProvider x */ + public function method11(): void {} + + /** @depends x */ + public function method12(): void {} + + /** @doesNotPerformAssertions x */ + public function method13(): void {} + + /** @excludeGlobalVariableFromBackup x */ + public function method14(): void {} + + /** @excludeStaticPropertyFromBackup x */ + public function method15(): void {} + + /** @group x */ + public function method16(): void {} + + /** @large x */ + public function method17(): void {} + + /** @medium x */ + public function method18(): void {} + + /** @postCondition x */ + public function method19(): void {} + + /** @preCondition x */ + public function method20(): void {} + + /** @preserveGlobalState x */ + public function method21(): void {} + + /** @requires x */ + public function method22(): void {} + + /** @runClassInSeparateProcess x */ + public function method23(): void {} + + /** @runInSeparateProcess x */ + public function method24(): void {} + + /** @runTestsInSeparateProcesses x */ + public function method25(): void {} + + /** @small x */ + public function method26(): void {} + + /** @test x */ + public function method27(): void {} + + /** @testdox x */ + public function method28(): void {} + + /** @testWith x */ + public function method29(): void {} + + /** @ticket x */ + public function method30(): void {} + + /** @uses x */ + public function method31(): void {} + + /** @usesDefaultClass x */ + public function method32(): void {} + } + """ + When I run Psalm + Then I see these errors + | Type | Message | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @after docblock tag, use #[After] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @afterClass docblock tag, use #[AfterClass] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @backupGlobals docblock tag, use #[BackupGlobals] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @backupStaticAttributes docblock tag, use #[BackupStaticProperties] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @backupStaticProperties docblock tag, use #[BackupStaticProperties] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @before docblock tag, use #[Before] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @beforeClass docblock tag, use #[BeforeClass] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @covers docblock tag, use #[CoversClass], #[CoversMethod] or #[CoversFunction] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @coversDefaultClass docblock tag, use #[CoversClass] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @coversNothing docblock tag, use #[CoversNothing] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @dataProvider docblock tag, use #[DataProvider] or #[DataProviderExternal] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @depends docblock tag, use #[Depends] or #[DependsExternal] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @doesNotPerformAssertions docblock tag, use #[DoesNotPerformAssertions] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @excludeGlobalVariableFromBackup docblock tag, use #[ExcludeGlobalVariableFromBackup] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @excludeStaticPropertyFromBackup docblock tag, use #[ExcludeStaticPropertyFromBackup] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @group docblock tag, use #[Group] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @large docblock tag, use #[Large] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @medium docblock tag, use #[Medium] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @postCondition docblock tag, use #[PostCondition] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @preCondition docblock tag, use #[PreCondition] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @preserveGlobalState docblock tag, use #[PreserveGlobalState] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @requires docblock tag, use #[RequiresPhp], #[RequiresPhpExtension], #[RequiresOperatingSystem] or another #[Requires*] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @runClassInSeparateProcess docblock tag, use #[RunClassInSeparateProcess] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @runInSeparateProcess docblock tag, use #[RunInSeparateProcess] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @runTestsInSeparateProcesses docblock tag, use #[RunTestsInSeparateProcesses] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @small docblock tag, use #[Small] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @test docblock tag, use #[Test] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @testdox docblock tag, use #[TestDox] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @testWith docblock tag, use #[TestWith] or #[TestWithJson] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @ticket docblock tag, use #[Ticket] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @uses docblock tag, use #[UsesClass], #[UsesMethod] or #[UsesFunction] instead | + | IgnoredDocblockMetadata | PHPUnit 12 ignores the @usesDefaultClass docblock tag, use #[UsesClass] instead | + And I see no other errors From fd8e8bd0fd36ef6d16d285edf8064d297efa1e0d Mon Sep 17 00:00:00 2001 From: Alies Lapatsin <5278175+alies-dev@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:21:50 +0100 Subject: [PATCH 2/3] Skip the methods without PHPUnit metadata in the per-class method loops #289 afterClassLikeVisit() records the methods a class-like declares with an attribute or a docblock that may hold a tag PHPUnit 11 reads, next to the before methods. Both AfterClassLikeAnalysis loops over declaring_method_ids skip the other methods, unless the test case names them test*: PHPUnit reads nothing from them. DocblockSpecials parses only the docblocks that pass the same check. --- src/DocblockSpecials.php | 28 +++++++++++- src/Hooks/DocblockMetadataHandler.php | 11 ++++- src/Hooks/TestCaseHandler.php | 66 +++++++++++++++++++++++---- 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/src/DocblockSpecials.php b/src/DocblockSpecials.php index 62d8ceb..9c19adf 100644 --- a/src/DocblockSpecials.php +++ b/src/DocblockSpecials.php @@ -32,6 +32,13 @@ final class DocblockSpecials 'usesDefaultClass' => true, ]; + /** + * Matches every tag PHPUnit 11 reads from a docblock (the keys of DocblockMetadataHandler::ATTRIBUTES) by its + * first letters, in any case. + */ + private const TAGS = '/@(?:after|backup|before|covers|dataProvider|depends|doesNotPerformAssertions|exclude|group' + . '|large|medium|postCondition|preCondition|preserveGlobalState|requires|run|small|test|ticket|uses)/i'; + /** * The tags PHPUnit 11 accepts. A malformed tag is ignored by PHPUnit, so it is not here. * @@ -50,7 +57,7 @@ public static function of(Node $node): array } /** - * Every tag, malformed or not. + * Every tag, malformed or not, of a docblock that may hold a tag PHPUnit 11 reads. * * @return array> tag => [[file line, value]] */ @@ -77,13 +84,30 @@ public static function malformed(Node $node): array return $malformed; } + /** + * Whether the docblock of the node may hold a tag PHPUnit 11 reads. Without one, of(), all() and malformed() find + * nothing. + */ + public static function mayHoldTags(Node $node): bool + { + $docblock = $node->getDocComment(); + + return $docblock !== null && self::docblockMayHoldTags($docblock); + } + + private static function docblockMayHoldTags(Doc $docblock): bool + { + // Psalm's DocblockParser removes every \r before it reads a tag + return \preg_match(self::TAGS, \str_replace("\r", '', $docblock->getText())) === 1; + } + /** * @return list [tag, file line, value, what is wrong with the tag] */ private static function parse(Node $node): array { $docblock = $node->getDocComment(); - if (!$docblock) { + if ($docblock === null || !self::docblockMayHoldTags($docblock)) { return []; } diff --git a/src/Hooks/DocblockMetadataHandler.php b/src/Hooks/DocblockMetadataHandler.php index fedaef0..a04b780 100644 --- a/src/Hooks/DocblockMetadataHandler.php +++ b/src/Hooks/DocblockMetadataHandler.php @@ -93,8 +93,17 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event // Inherited methods are reported with the class that declares them. A trait docblock or method is reported // once for every class using it, at the same location with the same message, which Psalm deduplicates. + $methods_with_metadata = []; foreach ($class_storage->declaring_method_ids as $declaring_method_id) { - $declaring_class = $codebase->classlike_storage_provider->get($declaring_method_id->fq_class_name); + $declaring_class_name = $declaring_method_id->fq_class_name; + $methods_with_metadata[$declaring_class_name] ??= TestCaseHandler::methodsWithMetadata( + $codebase->classlike_storage_provider->get($declaring_class_name), + ); + if (!isset($methods_with_metadata[$declaring_class_name][$declaring_method_id->method_name])) { + continue; + } + + $declaring_class = $codebase->classlike_storage_provider->get($declaring_class_name); $declaring_class_node = match (true) { \strtolower($declaring_class->name) === \strtolower($class_storage->name) => $class_node, $declaring_class->is_trait => $codebase->classlikes->getTraitNode($declaring_class->name), diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index 2e96f3e..fac8fd2 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -341,15 +341,23 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) $class_storage->sealed_methods = false; } + $metadata = (array) ($class_storage->custom_metadata[__NAMESPACE__] ?? []); $before = self::getBeforeMethods($class_storage, $class_node, $aliases); if ($before !== []) { - $class_storage->custom_metadata[__NAMESPACE__] = ['before' => $before]; + $metadata['before'] = $before; } $file_path = $statements_source->getFilePath(); $file_storage = $codebase->file_storage_provider->get($file_path); + $with_metadata = []; foreach ($class_node->getMethods() as $method) { + // any attribute: at analysis, the aliases also hold the imports written after the class + if ($method->attrGroups === [] && !DocblockSpecials::mayHoldTags($method)) { + continue; + } + $with_metadata[$method->name->toLowerString()] = true; + $providers = self::getDataProviders($method, $aliases, $aliases, $class_storage); foreach ($providers as $provider) { if ($provider['class'] === null) { @@ -379,6 +387,15 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) 'depends' => self::getDependencyTargets($method, $aliases, $class_storage) !== [], ]; } + + // a stub and the file it refines are visited into the same storage, the set covers both + if ($with_metadata !== []) { + $metadata['with_metadata'] = $with_metadata + (array) ($metadata['with_metadata'] ?? []); + } + + if ($metadata !== []) { + $class_storage->custom_metadata[__NAMESPACE__] = $metadata; + } } #[\Override] @@ -432,17 +449,25 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event ); } + $methods_with_metadata = []; foreach ($class_storage->declaring_method_ids as $method_name_lc => $declaring_method_id) { - $method_name = $codebase->getCasedMethodId($class_storage->name . '::' . $method_name_lc); - $method_storage = $codebase->methods->getStorage($declaring_method_id); - [$declaring_method_class, $declaring_method_name] = \explode('::', (string) $declaring_method_id); - $declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_method_class); + $declaring_method_class = $declaring_method_id->fq_class_name; + $declaring_method_name = $declaring_method_id->method_name; + $methods_with_metadata[$declaring_method_class] ??= self::methodsWithMetadata( + $codebase->classlike_storage_provider->get($declaring_method_class), + ); - $declaring_class_node = $class_node; - if ($declaring_class_storage->is_trait) { - $declaring_class_node = $codebase->classlikes->getTraitNode($declaring_class_storage->name); + // PHPUnit runs the methods the test case names test*, a trait alias included. Of the others it only reads + // the metadata of their declaration. + if ( + !isset($methods_with_metadata[$declaring_method_class][$declaring_method_name]) + && !\str_starts_with($method_name_lc, 'test') + ) { + continue; } + $method_storage = $codebase->methods->getStorage($declaring_method_id); + $declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_method_class); if (!$method_storage->location) { continue; } @@ -461,6 +486,10 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event continue; } + $declaring_class_node = $declaring_class_storage->is_trait + ? $codebase->classlikes->getTraitNode($declaring_class_storage->name) + : $class_node; + $stmt_method = $declaring_class_node->getMethod($declaring_method_name); if (!$stmt_method) { @@ -499,6 +528,8 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event continue; } + $method_name = $codebase->getCasedMethodId($class_storage->name . '::' . $method_name_lc); + $dependency_values = self::countDependencyValues( $codebase, $stmt_method, @@ -1739,6 +1770,25 @@ public static function isPublicMethod( return $visibility === ClassLikeAnalyzer::VISIBILITY_PUBLIC; } + /** + * An upper bound of the methods the class-like declares with PHPUnit metadata, as afterClassLikeVisit() found + * them: a method outside it has no attribute and no docblock tag PHPUnit 11 reads. The methods in it and the ones + * a test case names test* still go through every check. + * + * @return array + * + * @psalm-mutation-free + * + * @internal + */ + public static function methodsWithMetadata(ClassLikeStorage $storage): array + { + $metadata = (array) ($storage->custom_metadata[__NAMESPACE__] ?? []); + + /** @var array */ + return $metadata['with_metadata'] ?? []; + } + /** * PHPUnit's ParserChain ignores docblock annotations on a class or method that has any PHPUnit attribute. * From c4ec076718ab7e2d52f06458cb173b9cd4e99a3e Mon Sep 17 00:00:00 2001 From: Alies Lapatsin <5278175+alies-dev@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:47:46 +0100 Subject: [PATCH 3/3] Keep checking every method of a storage cached without the set #289 Storage cached by an older version of the plugin has no with_metadata key. Psalm keeps that cache when only the plugin changes and the project's composer.lock does not (a global install), so an absent key means unknown, not empty. --- src/Hooks/DocblockMetadataHandler.php | 11 +++++---- src/Hooks/TestCaseHandler.php | 32 +++++++++++++-------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Hooks/DocblockMetadataHandler.php b/src/Hooks/DocblockMetadataHandler.php index a04b780..236df88 100644 --- a/src/Hooks/DocblockMetadataHandler.php +++ b/src/Hooks/DocblockMetadataHandler.php @@ -96,10 +96,13 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event $methods_with_metadata = []; foreach ($class_storage->declaring_method_ids as $declaring_method_id) { $declaring_class_name = $declaring_method_id->fq_class_name; - $methods_with_metadata[$declaring_class_name] ??= TestCaseHandler::methodsWithMetadata( - $codebase->classlike_storage_provider->get($declaring_class_name), - ); - if (!isset($methods_with_metadata[$declaring_class_name][$declaring_method_id->method_name])) { + if (!\array_key_exists($declaring_class_name, $methods_with_metadata)) { + $methods_with_metadata[$declaring_class_name] = TestCaseHandler::methodsWithMetadata( + $codebase->classlike_storage_provider->get($declaring_class_name), + ); + } + $with_metadata = $methods_with_metadata[$declaring_class_name]; + if ($with_metadata !== null && !isset($with_metadata[$declaring_method_id->method_name])) { continue; } diff --git a/src/Hooks/TestCaseHandler.php b/src/Hooks/TestCaseHandler.php index fac8fd2..94ca7c0 100644 --- a/src/Hooks/TestCaseHandler.php +++ b/src/Hooks/TestCaseHandler.php @@ -389,13 +389,8 @@ public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) } // a stub and the file it refines are visited into the same storage, the set covers both - if ($with_metadata !== []) { - $metadata['with_metadata'] = $with_metadata + (array) ($metadata['with_metadata'] ?? []); - } - - if ($metadata !== []) { - $class_storage->custom_metadata[__NAMESPACE__] = $metadata; - } + $metadata['with_metadata'] = $with_metadata + (array) ($metadata['with_metadata'] ?? []); + $class_storage->custom_metadata[__NAMESPACE__] = $metadata; } #[\Override] @@ -453,14 +448,18 @@ public static function afterStatementAnalysis(AfterClassLikeAnalysisEvent $event foreach ($class_storage->declaring_method_ids as $method_name_lc => $declaring_method_id) { $declaring_method_class = $declaring_method_id->fq_class_name; $declaring_method_name = $declaring_method_id->method_name; - $methods_with_metadata[$declaring_method_class] ??= self::methodsWithMetadata( - $codebase->classlike_storage_provider->get($declaring_method_class), - ); + if (!\array_key_exists($declaring_method_class, $methods_with_metadata)) { + $methods_with_metadata[$declaring_method_class] = self::methodsWithMetadata( + $codebase->classlike_storage_provider->get($declaring_method_class), + ); + } + $with_metadata = $methods_with_metadata[$declaring_method_class]; // PHPUnit runs the methods the test case names test*, a trait alias included. Of the others it only reads // the metadata of their declaration. if ( - !isset($methods_with_metadata[$declaring_method_class][$declaring_method_name]) + $with_metadata !== null + && !isset($with_metadata[$declaring_method_name]) && !\str_starts_with($method_name_lc, 'test') ) { continue; @@ -1773,20 +1772,21 @@ public static function isPublicMethod( /** * An upper bound of the methods the class-like declares with PHPUnit metadata, as afterClassLikeVisit() found * them: a method outside it has no attribute and no docblock tag PHPUnit 11 reads. The methods in it and the ones - * a test case names test* still go through every check. + * a test case names test* still go through every check. Null when unknown: the storage was cached by an older + * version of the plugin. * - * @return array + * @return array|null * * @psalm-mutation-free * * @internal */ - public static function methodsWithMetadata(ClassLikeStorage $storage): array + public static function methodsWithMetadata(ClassLikeStorage $storage): ?array { $metadata = (array) ($storage->custom_metadata[__NAMESPACE__] ?? []); - /** @var array */ - return $metadata['with_metadata'] ?? []; + /** @var array|null */ + return $metadata['with_metadata'] ?? null; } /**