From 71704041a9467189512ae050b13e47127df0f7a4 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Sun, 6 Oct 2019 19:51:34 +0200 Subject: [PATCH 01/15] Let the DocBlock::ofMethod handle an optional className Fixes #3879 --- src/Util/Annotation/DocBlock.php | 4 ++-- src/Util/Annotation/Registry.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Util/Annotation/DocBlock.php b/src/Util/Annotation/DocBlock.php index 027737c8d9b..c96971beeab 100644 --- a/src/Util/Annotation/DocBlock.php +++ b/src/Util/Annotation/DocBlock.php @@ -101,7 +101,7 @@ public static function ofClass(\ReflectionClass $class): self ); } - public static function ofMethod(\ReflectionMethod $method): self + public static function ofMethod(\ReflectionMethod $method, string $className = null): self { return new self( (string) $method->getDocComment(), @@ -111,7 +111,7 @@ public static function ofMethod(\ReflectionMethod $method): self $method->getEndLine(), $method->getFileName(), $method->getName(), - $method->getDeclaringClass()->getName() + $className ?? $method->getDeclaringClass()->getName() ); } diff --git a/src/Util/Annotation/Registry.php b/src/Util/Annotation/Registry.php index 795dbf6a93c..fa6cf36414e 100644 --- a/src/Util/Annotation/Registry.php +++ b/src/Util/Annotation/Registry.php @@ -80,6 +80,6 @@ public function forMethod(string $class, string $method): DocBlock ); } - return $this->methodDocBlocks[$class][$method] = DocBlock::ofMethod($reflection); + return $this->methodDocBlocks[$class][$method] = DocBlock::ofMethod($reflection, $class); } } From c39d04e64be028f5e90020a72b6a498b24ec5664 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Sun, 6 Oct 2019 22:34:40 +0200 Subject: [PATCH 02/15] Make psalm happy --- src/Util/Annotation/DocBlock.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Util/Annotation/DocBlock.php b/src/Util/Annotation/DocBlock.php index c96971beeab..3e4dcdd8c89 100644 --- a/src/Util/Annotation/DocBlock.php +++ b/src/Util/Annotation/DocBlock.php @@ -101,6 +101,9 @@ public static function ofClass(\ReflectionClass $class): self ); } + /** + * @psalm-param class-string $className + */ public static function ofMethod(\ReflectionMethod $method, string $className = null): self { return new self( From 48d3752fcdf7581313afcb23f08aea5e30ce15e8 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Sun, 6 Oct 2019 23:03:19 +0200 Subject: [PATCH 03/15] Make test to test abstract dataproviders and dataproviders in abstract classes --- ...bstractVariousIterableDataProviderTest.php | 56 +++++++++++++++++++ .../VariousIterableDataProviderTest.php | 8 +-- tests/unit/Util/TestTest.php | 27 +++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 tests/_files/AbstractVariousIterableDataProviderTest.php diff --git a/tests/_files/AbstractVariousIterableDataProviderTest.php b/tests/_files/AbstractVariousIterableDataProviderTest.php new file mode 100644 index 00000000000..776e8bf840a --- /dev/null +++ b/tests/_files/AbstractVariousIterableDataProviderTest.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +abstract class AbstractVariousIterableDataProviderTest +{ + abstract public function asArrayProvider(); + + abstract public function asIteratorProvider(); + + abstract public function asTraversableProvider(); + + public function asArrayProviderInParent() + { + return [ + ['J'], + ['K'], + ['L'], + ]; + } + + public function asIteratorProviderInParent() + { + yield ['M']; + + yield ['N']; + + yield ['O']; + } + + public function asTraversableProviderInParent() + { + return new WrapperIteratorAggregate([ + ['P'], + ['Q'], + ['R'], + ]); + } + + /** + * @dataProvider asArrayProvider + * @dataProvider asIteratorProvider + * @dataProvider asTraversableProvider + * @dataProvider asArrayProviderInParent + * @dataProvider asIteratorProviderInParent + * @dataProvider asTraversableProviderInParent + */ + public function testAbstract(): void + { + } +} diff --git a/tests/_files/VariousIterableDataProviderTest.php b/tests/_files/VariousIterableDataProviderTest.php index b84e0ccc387..a5a95b2eea9 100644 --- a/tests/_files/VariousIterableDataProviderTest.php +++ b/tests/_files/VariousIterableDataProviderTest.php @@ -7,9 +7,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class VariousIterableDataProviderTest +class VariousIterableDataProviderTest extends AbstractVariousIterableDataProviderTest { - public static function asArrayProvider() + public function asArrayProvider() { return [ ['A'], @@ -18,7 +18,7 @@ public static function asArrayProvider() ]; } - public static function asIteratorProvider() + public function asIteratorProvider() { yield ['D']; @@ -27,7 +27,7 @@ public static function asIteratorProvider() yield ['F']; } - public static function asTraversableProvider() + public function asTraversableProvider() { return new WrapperIteratorAggregate([ ['G'], diff --git a/tests/unit/Util/TestTest.php b/tests/unit/Util/TestTest.php index 27202ead191..a19c4d8f81f 100644 --- a/tests/unit/Util/TestTest.php +++ b/tests/unit/Util/TestTest.php @@ -911,6 +911,33 @@ public function testMultipleYieldIteratorDataProviders(): void $this->assertEquals(3, $cCount); } + public function testWithAbstractVariousIterableDataProviders(): void + { + $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'testAbstract'); + + $this->assertEquals([ + ['A'], + ['B'], + ['C'], + ['D'], + ['E'], + ['F'], + ['G'], + ['H'], + ['I'], + ['J'], + ['K'], + ['L'], + ['M'], + ['N'], + ['O'], + ['P'], + ['Q'], + ['R'], + + ], $dataSets); + } + public function testWithVariousIterableDataProviders(): void { $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'test'); From d3d5909dd88731420e3060f06da39dae074af97c Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Sun, 6 Oct 2019 23:08:43 +0200 Subject: [PATCH 04/15] Correct psalm-param hinting in /Util/Annotation/Registry --- src/Util/Annotation/Registry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util/Annotation/Registry.php b/src/Util/Annotation/Registry.php index fa6cf36414e..bdf2f698a59 100644 --- a/src/Util/Annotation/Registry.php +++ b/src/Util/Annotation/Registry.php @@ -62,7 +62,7 @@ public function forClassName(string $class): DocBlock /** * @throws Exception - * @psalm-param class-string $className + * @psalm-param class-string $class */ public function forMethod(string $class, string $method): DocBlock { From d5c349cbd24d5fa5041608aed4ae5f7014ef4ab1 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 10:44:50 +0200 Subject: [PATCH 05/15] More psalm class-string typehinting --- src/Framework/TestBuilder.php | 2 ++ src/Util/Test.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Framework/TestBuilder.php b/src/Framework/TestBuilder.php index 5ee7bf3a32a..354abc44d59 100644 --- a/src/Framework/TestBuilder.php +++ b/src/Framework/TestBuilder.php @@ -131,11 +131,13 @@ private function appendExceptionMessageIfAvailable(\Throwable $e, string $messag return $message; } + /** @psalm-param class-string $className **/ private function buildTestWithoutData(string $className) { return new $className; } + /** @psalm-param class-string $className **/ private function buildDataProviderTestSuite( string $methodName, string $className, diff --git a/src/Util/Test.php b/src/Util/Test.php index aed3a4f5ee9..68ce039f788 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -78,6 +78,7 @@ public static function describeAsString(\PHPUnit\Framework\Test $test): string * @throws CodeCoverageException * * @return array|bool + * @psalm-param class-string $className */ public static function getLinesToBeCovered(string $className, string $methodName) { @@ -97,6 +98,7 @@ public static function getLinesToBeCovered(string $className, string $methodName * Returns lines of code specified with the @uses annotation. * * @throws CodeCoverageException + * @psalm-param class-string $className */ public static function getLinesToBeUsed(string $className, string $methodName): array { @@ -132,6 +134,7 @@ public static function requiresCodeCoverageDataCollection(TestCase $test): bool /** * @throws Exception + * @psalm-param class-string $className */ public static function getRequirements(string $className, string $methodName): array { @@ -146,6 +149,7 @@ public static function getRequirements(string $className, string $methodName): a * * @throws Exception * @throws Warning + * @psalm-param class-string $className */ public static function getMissingRequirements(string $className, string $methodName): array { @@ -282,6 +286,7 @@ public static function getMissingRequirements(string $className, string $methodN * * @deprecated * @codeCoverageIgnore + * @psalm-param class-string $className */ public static function getExpectedException(string $className, string $methodName) { @@ -292,12 +297,16 @@ public static function getExpectedException(string $className, string $methodNam * Returns the provided data for a method. * * @throws Exception + * @psalm-param class-string $className */ public static function getProvidedData(string $className, string $methodName): ?array { return Registry::getInstance()->forMethod($className, $methodName)->getProvidedData(); } + /** + * @psalm-param class-string $className + */ public static function parseTestMethodAnnotations(string $className, ?string $methodName = ''): array { $registry = Registry::getInstance(); @@ -319,11 +328,15 @@ public static function parseTestMethodAnnotations(string $className, ?string $me ]; } + /** + * @psalm-param class-string $className + */ public static function getInlineAnnotations(string $className, string $methodName): array { return Registry::getInstance()->forMethod($className, $methodName)->getInlineAnnotations(); } + /** @psalm-param class-string $className **/ public static function getBackupSettings(string $className, string $methodName): array { return [ @@ -340,6 +353,7 @@ public static function getBackupSettings(string $className, string $methodName): ]; } + /** @psalm-param class-string $className **/ public static function getDependencies(string $className, string $methodName): array { $annotations = self::parseTestMethodAnnotations( @@ -359,6 +373,7 @@ public static function getDependencies(string $className, string $methodName): a return \array_unique($dependencies); } + /** @psalm-param class-string $className **/ public static function getGroups(string $className, ?string $methodName = ''): array { $annotations = self::parseTestMethodAnnotations( @@ -403,6 +418,7 @@ public static function getGroups(string $className, ?string $methodName = ''): a return \array_unique(\array_merge([], ...$groups)); } + /** @psalm-param class-string $className **/ public static function getSize(string $className, ?string $methodName): int { $groups = \array_flip(self::getGroups($className, $methodName)); @@ -422,6 +438,7 @@ public static function getSize(string $className, ?string $methodName): int return self::UNKNOWN; } + /** @psalm-param class-string $className **/ public static function getProcessIsolationSettings(string $className, string $methodName): bool { $annotations = self::parseTestMethodAnnotations( @@ -432,6 +449,7 @@ public static function getProcessIsolationSettings(string $className, string $me return isset($annotations['class']['runTestsInSeparateProcesses']) || isset($annotations['method']['runInSeparateProcess']); } + /** @psalm-param class-string $className **/ public static function getClassProcessIsolationSettings(string $className, string $methodName): bool { $annotations = self::parseTestMethodAnnotations( @@ -442,6 +460,7 @@ public static function getClassProcessIsolationSettings(string $className, strin return isset($annotations['class']['runClassInSeparateProcess']); } + /** @psalm-param class-string $className **/ public static function getPreserveGlobalStateSettings(string $className, string $methodName): ?bool { return self::getBooleanAnnotationSetting( @@ -522,6 +541,7 @@ public static function isTestMethod(\ReflectionMethod $method): bool /** * @throws CodeCoverageException + * @psalm-param class-string $className */ private static function getLinesToBeCoveredOrUsed(string $className, string $methodName, string $mode): array { @@ -588,6 +608,7 @@ private static function emptyHookMethodsArray(): array ]; } + /** @psalm-param class-string $className **/ private static function getBooleanAnnotationSetting(string $className, ?string $methodName, string $settingName): ?bool { $annotations = self::parseTestMethodAnnotations( From e59d87b55037c6875764a8a1cf1433e848d6386e Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 11:21:11 +0200 Subject: [PATCH 06/15] Revert "Make test to test abstract dataproviders and dataproviders in abstract classes" This reverts commit 48d3752fcdf7581313afcb23f08aea5e30ce15e8. --- ...bstractVariousIterableDataProviderTest.php | 56 ------------------- .../VariousIterableDataProviderTest.php | 8 +-- tests/unit/Util/TestTest.php | 27 --------- 3 files changed, 4 insertions(+), 87 deletions(-) delete mode 100644 tests/_files/AbstractVariousIterableDataProviderTest.php diff --git a/tests/_files/AbstractVariousIterableDataProviderTest.php b/tests/_files/AbstractVariousIterableDataProviderTest.php deleted file mode 100644 index 776e8bf840a..00000000000 --- a/tests/_files/AbstractVariousIterableDataProviderTest.php +++ /dev/null @@ -1,56 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -abstract class AbstractVariousIterableDataProviderTest -{ - abstract public function asArrayProvider(); - - abstract public function asIteratorProvider(); - - abstract public function asTraversableProvider(); - - public function asArrayProviderInParent() - { - return [ - ['J'], - ['K'], - ['L'], - ]; - } - - public function asIteratorProviderInParent() - { - yield ['M']; - - yield ['N']; - - yield ['O']; - } - - public function asTraversableProviderInParent() - { - return new WrapperIteratorAggregate([ - ['P'], - ['Q'], - ['R'], - ]); - } - - /** - * @dataProvider asArrayProvider - * @dataProvider asIteratorProvider - * @dataProvider asTraversableProvider - * @dataProvider asArrayProviderInParent - * @dataProvider asIteratorProviderInParent - * @dataProvider asTraversableProviderInParent - */ - public function testAbstract(): void - { - } -} diff --git a/tests/_files/VariousIterableDataProviderTest.php b/tests/_files/VariousIterableDataProviderTest.php index a5a95b2eea9..b84e0ccc387 100644 --- a/tests/_files/VariousIterableDataProviderTest.php +++ b/tests/_files/VariousIterableDataProviderTest.php @@ -7,9 +7,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class VariousIterableDataProviderTest extends AbstractVariousIterableDataProviderTest +class VariousIterableDataProviderTest { - public function asArrayProvider() + public static function asArrayProvider() { return [ ['A'], @@ -18,7 +18,7 @@ public function asArrayProvider() ]; } - public function asIteratorProvider() + public static function asIteratorProvider() { yield ['D']; @@ -27,7 +27,7 @@ public function asIteratorProvider() yield ['F']; } - public function asTraversableProvider() + public static function asTraversableProvider() { return new WrapperIteratorAggregate([ ['G'], diff --git a/tests/unit/Util/TestTest.php b/tests/unit/Util/TestTest.php index a19c4d8f81f..27202ead191 100644 --- a/tests/unit/Util/TestTest.php +++ b/tests/unit/Util/TestTest.php @@ -911,33 +911,6 @@ public function testMultipleYieldIteratorDataProviders(): void $this->assertEquals(3, $cCount); } - public function testWithAbstractVariousIterableDataProviders(): void - { - $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'testAbstract'); - - $this->assertEquals([ - ['A'], - ['B'], - ['C'], - ['D'], - ['E'], - ['F'], - ['G'], - ['H'], - ['I'], - ['J'], - ['K'], - ['L'], - ['M'], - ['N'], - ['O'], - ['P'], - ['Q'], - ['R'], - - ], $dataSets); - } - public function testWithVariousIterableDataProviders(): void { $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'test'); From 78811f4cf9c1b18b739469013fd314fd200a8928 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 11:50:04 +0200 Subject: [PATCH 07/15] Make psalm and csFixer a bit happier --- src/Framework/TestBuilder.php | 4 ++-- src/Util/Annotation/DocBlock.php | 4 ++-- src/Util/Test.php | 16 ++++++++-------- src/Util/TestDox/NamePrettifier.php | 1 + 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Framework/TestBuilder.php b/src/Framework/TestBuilder.php index 354abc44d59..61894f7f7cf 100644 --- a/src/Framework/TestBuilder.php +++ b/src/Framework/TestBuilder.php @@ -131,13 +131,13 @@ private function appendExceptionMessageIfAvailable(\Throwable $e, string $messag return $message; } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ private function buildTestWithoutData(string $className) { return new $className; } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ private function buildDataProviderTestSuite( string $methodName, string $className, diff --git a/src/Util/Annotation/DocBlock.php b/src/Util/Annotation/DocBlock.php index 3e4dcdd8c89..557d9b8ab74 100644 --- a/src/Util/Annotation/DocBlock.php +++ b/src/Util/Annotation/DocBlock.php @@ -104,7 +104,7 @@ public static function ofClass(\ReflectionClass $class): self /** * @psalm-param class-string $className */ - public static function ofMethod(\ReflectionMethod $method, string $className = null): self + public static function ofMethod(\ReflectionMethod $method, string $classNameInHierarchy): self { return new self( (string) $method->getDocComment(), @@ -114,7 +114,7 @@ public static function ofMethod(\ReflectionMethod $method, string $className = n $method->getEndLine(), $method->getFileName(), $method->getName(), - $className ?? $method->getDeclaringClass()->getName() + $classNameInHierarchy ); } diff --git a/src/Util/Test.php b/src/Util/Test.php index 68ce039f788..cc066cc9e4e 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -336,7 +336,7 @@ public static function getInlineAnnotations(string $className, string $methodNam return Registry::getInstance()->forMethod($className, $methodName)->getInlineAnnotations(); } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ public static function getBackupSettings(string $className, string $methodName): array { return [ @@ -353,7 +353,7 @@ public static function getBackupSettings(string $className, string $methodName): ]; } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ public static function getDependencies(string $className, string $methodName): array { $annotations = self::parseTestMethodAnnotations( @@ -373,7 +373,7 @@ public static function getDependencies(string $className, string $methodName): a return \array_unique($dependencies); } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ public static function getGroups(string $className, ?string $methodName = ''): array { $annotations = self::parseTestMethodAnnotations( @@ -418,7 +418,7 @@ public static function getGroups(string $className, ?string $methodName = ''): a return \array_unique(\array_merge([], ...$groups)); } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ public static function getSize(string $className, ?string $methodName): int { $groups = \array_flip(self::getGroups($className, $methodName)); @@ -438,7 +438,7 @@ public static function getSize(string $className, ?string $methodName): int return self::UNKNOWN; } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ public static function getProcessIsolationSettings(string $className, string $methodName): bool { $annotations = self::parseTestMethodAnnotations( @@ -449,7 +449,7 @@ public static function getProcessIsolationSettings(string $className, string $me return isset($annotations['class']['runTestsInSeparateProcesses']) || isset($annotations['method']['runInSeparateProcess']); } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ public static function getClassProcessIsolationSettings(string $className, string $methodName): bool { $annotations = self::parseTestMethodAnnotations( @@ -460,7 +460,7 @@ public static function getClassProcessIsolationSettings(string $className, strin return isset($annotations['class']['runClassInSeparateProcess']); } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ public static function getPreserveGlobalStateSettings(string $className, string $methodName): ?bool { return self::getBooleanAnnotationSetting( @@ -608,7 +608,7 @@ private static function emptyHookMethodsArray(): array ]; } - /** @psalm-param class-string $className **/ + /** @psalm-param class-string $className */ private static function getBooleanAnnotationSetting(string $className, ?string $methodName, string $settingName): ?bool { $annotations = self::parseTestMethodAnnotations( diff --git a/src/Util/TestDox/NamePrettifier.php b/src/Util/TestDox/NamePrettifier.php index fa2b1c2b449..87d2a88e115 100644 --- a/src/Util/TestDox/NamePrettifier.php +++ b/src/Util/TestDox/NamePrettifier.php @@ -37,6 +37,7 @@ public function __construct($useColor = false) /** * Prettifies the name of a test class. + * @psalm-param class-string $className */ public function prettifyTestClass(string $className): string { From 0d4105514f3c0d6f10faef894f2d3f79a7230a5d Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 11:50:35 +0200 Subject: [PATCH 08/15] Test various different ways of declaring dataProviders --- ...bstractVariousIterableDataProviderTest.php | 62 +++++++++++++++ .../VariousIterableDataProviderTest.php | 57 ++++++++++++-- tests/unit/Util/TestTest.php | 75 ++++++++++++++++++- 3 files changed, 186 insertions(+), 8 deletions(-) create mode 100644 tests/_files/AbstractVariousIterableDataProviderTest.php diff --git a/tests/_files/AbstractVariousIterableDataProviderTest.php b/tests/_files/AbstractVariousIterableDataProviderTest.php new file mode 100644 index 00000000000..ac2f1d4fc5a --- /dev/null +++ b/tests/_files/AbstractVariousIterableDataProviderTest.php @@ -0,0 +1,62 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +abstract class AbstractVariousIterableDataProviderTest +{ + abstract public function asArrayProvider(); + + abstract public function asIteratorProvider(); + + abstract public function asTraversableProvider(); + + public function asArrayProviderInParent() + { + return [ + ['J'], + ['K'], + ['L'], + ]; + } + + public function asIteratorProviderInParent() + { + yield ['M']; + + yield ['N']; + + yield ['O']; + } + + public function asTraversableProviderInParent() + { + return new WrapperIteratorAggregate([ + ['P'], + ['Q'], + ['R'], + ]); + } + + /** + * @dataProvider asArrayProvider + * @dataProvider asIteratorProvider + * @dataProvider asTraversableProvider + */ + public function testAbstract(): void + { + } + + /** + * @dataProvider asArrayProviderInParent + * @dataProvider asIteratorProviderInParent + * @dataProvider asTraversableProviderInParent + */ + public function testInParent(): void + { + } +} diff --git a/tests/_files/VariousIterableDataProviderTest.php b/tests/_files/VariousIterableDataProviderTest.php index b84e0ccc387..cc688fa1971 100644 --- a/tests/_files/VariousIterableDataProviderTest.php +++ b/tests/_files/VariousIterableDataProviderTest.php @@ -7,9 +7,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class VariousIterableDataProviderTest +class VariousIterableDataProviderTest extends AbstractVariousIterableDataProviderTest { - public static function asArrayProvider() + public static function asArrayStaticProvider() { return [ ['A'], @@ -18,7 +18,7 @@ public static function asArrayProvider() ]; } - public static function asIteratorProvider() + public static function asIteratorStaticProvider() { yield ['D']; @@ -27,7 +27,7 @@ public static function asIteratorProvider() yield ['F']; } - public static function asTraversableProvider() + public static function asTraversableStaticProvider() { return new WrapperIteratorAggregate([ ['G'], @@ -36,12 +36,57 @@ public static function asTraversableProvider() ]); } + /** + * @dataProvider asArrayStaticProvider + * @dataProvider asIteratorStaticProvider + * @dataProvider asTraversableStaticProvider + */ + public function testStatic(): void + { + } + + public function asArrayProvider() + { + return [ + ['S'], + ['T'], + ['U'], + ]; + } + + public function asIteratorProvider() + { + yield ['V']; + + yield ['W']; + + yield ['X']; + } + + public function asTraversableProvider() + { + return new WrapperIteratorAggregate([ + ['Y'], + ['Z'], + ['P'], + ]); + } + /** * @dataProvider asArrayProvider * @dataProvider asIteratorProvider * @dataProvider asTraversableProvider */ - public function test(): void + public function testNonStatic(): void { - } + } + + /** + * @dataProvider asArrayProviderInParent + * @dataProvider asIteratorProviderInParent + * @dataProvider asTraversableProviderInParent + */ + public function testFromParent(): void + { + } } diff --git a/tests/unit/Util/TestTest.php b/tests/unit/Util/TestTest.php index 27202ead191..7fc8a923eb6 100644 --- a/tests/unit/Util/TestTest.php +++ b/tests/unit/Util/TestTest.php @@ -911,9 +911,63 @@ public function testMultipleYieldIteratorDataProviders(): void $this->assertEquals(3, $cCount); } - public function testWithVariousIterableDataProviders(): void + public function testWithVariousIterableDataProvidersFromParent(): void { - $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'test'); + $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'testFromParent'); + + $this->assertEquals([ + ['J'], + ['K'], + ['L'], + ['M'], + ['N'], + ['O'], + ['P'], + ['Q'], + ['R'], + + ], $dataSets); + } + + public function testWithVariousIterableDataProvidersInParent(): void + { + $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'testInParent'); + + $this->assertEquals([ + ['J'], + ['K'], + ['L'], + ['M'], + ['N'], + ['O'], + ['P'], + ['Q'], + ['R'], + + ], $dataSets); + } + + public function testWithVariousIterableAbstractDataProviders(): void + { + $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'testAbstract'); + + $this->assertEquals([ + ['S'], + ['T'], + ['U'], + ['V'], + ['W'], + ['X'], + ['Y'], + ['Z'], + ['P'], + + ], $dataSets); + } + + public function testWithVariousIterableStaticDataProviders(): void + { + $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'testStatic'); $this->assertEquals([ ['A'], @@ -928,6 +982,23 @@ public function testWithVariousIterableDataProviders(): void ], $dataSets); } + public function testWithVariousIterableNonStaticDataProviders(): void + { + $dataSets = Test::getProvidedData(\VariousIterableDataProviderTest::class, 'testNonStatic'); + + $this->assertEquals([ + ['S'], + ['T'], + ['U'], + ['V'], + ['W'], + ['X'], + ['Y'], + ['Z'], + ['P'], + ], $dataSets); + } + public function testWithDuplicateKeyDataProviders(): void { $this->expectException(InvalidDataProviderException::class); From e6f1e6d89578057aed2f19c5beb8350236e9a619 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 12:02:07 +0200 Subject: [PATCH 09/15] Codestyle fixed --- src/Framework/DataProviderTestSuite.php | 1 + src/Util/Annotation/DocBlock.php | 2 +- src/Util/TestDox/NamePrettifier.php | 1 + tests/_files/VariousIterableDataProviderTest.php | 8 ++++---- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Framework/DataProviderTestSuite.php b/src/Framework/DataProviderTestSuite.php index a65dc34c372..0058c3fc18d 100644 --- a/src/Framework/DataProviderTestSuite.php +++ b/src/Framework/DataProviderTestSuite.php @@ -56,6 +56,7 @@ public function getSize(): int { [$className, $methodName] = \explode('::', $this->getName()); + /** @psalm-suppress ArgumentTypeCoercion */ return TestUtil::getSize($className, $methodName); } } diff --git a/src/Util/Annotation/DocBlock.php b/src/Util/Annotation/DocBlock.php index 557d9b8ab74..38471999ef7 100644 --- a/src/Util/Annotation/DocBlock.php +++ b/src/Util/Annotation/DocBlock.php @@ -102,7 +102,7 @@ public static function ofClass(\ReflectionClass $class): self } /** - * @psalm-param class-string $className + * @psalm-param class-string $classNameInHierarchy */ public static function ofMethod(\ReflectionMethod $method, string $classNameInHierarchy): self { diff --git a/src/Util/TestDox/NamePrettifier.php b/src/Util/TestDox/NamePrettifier.php index 87d2a88e115..b9175d84188 100644 --- a/src/Util/TestDox/NamePrettifier.php +++ b/src/Util/TestDox/NamePrettifier.php @@ -37,6 +37,7 @@ public function __construct($useColor = false) /** * Prettifies the name of a test class. + * * @psalm-param class-string $className */ public function prettifyTestClass(string $className): string diff --git a/tests/_files/VariousIterableDataProviderTest.php b/tests/_files/VariousIterableDataProviderTest.php index cc688fa1971..8aa27ccdc07 100644 --- a/tests/_files/VariousIterableDataProviderTest.php +++ b/tests/_files/VariousIterableDataProviderTest.php @@ -79,14 +79,14 @@ public function asTraversableProvider() */ public function testNonStatic(): void { - } + } /** * @dataProvider asArrayProviderInParent * @dataProvider asIteratorProviderInParent * @dataProvider asTraversableProviderInParent */ - public function testFromParent(): void - { - } + public function testFromParent(): void + { + } } From 79c42c9bff7390fbc649578b89dcbef93633f33c Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 12:07:12 +0200 Subject: [PATCH 10/15] Last codestyle fix (I hope) --- src/Framework/DataProviderTestSuite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Framework/DataProviderTestSuite.php b/src/Framework/DataProviderTestSuite.php index 0058c3fc18d..18800be56ca 100644 --- a/src/Framework/DataProviderTestSuite.php +++ b/src/Framework/DataProviderTestSuite.php @@ -56,7 +56,7 @@ public function getSize(): int { [$className, $methodName] = \explode('::', $this->getName()); - /** @psalm-suppress ArgumentTypeCoercion */ + /* @psalm-suppress ArgumentTypeCoercion */ return TestUtil::getSize($className, $methodName); } } From f57f550268ef23ccb74c6b4da6f4e0cb4d515179 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 12:13:12 +0200 Subject: [PATCH 11/15] Revert "Last codestyle fix (I hope)" This reverts commit 79c42c9bff7390fbc649578b89dcbef93633f33c. --- src/Framework/DataProviderTestSuite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Framework/DataProviderTestSuite.php b/src/Framework/DataProviderTestSuite.php index 18800be56ca..0058c3fc18d 100644 --- a/src/Framework/DataProviderTestSuite.php +++ b/src/Framework/DataProviderTestSuite.php @@ -56,7 +56,7 @@ public function getSize(): int { [$className, $methodName] = \explode('::', $this->getName()); - /* @psalm-suppress ArgumentTypeCoercion */ + /** @psalm-suppress ArgumentTypeCoercion */ return TestUtil::getSize($className, $methodName); } } From 058d6abdc0434e8e034587137d34fcae1c82c42e Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 12:20:25 +0200 Subject: [PATCH 12/15] add class to DocBlock::ofMethod in TestTest --- tests/unit/Util/TestTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/Util/TestTest.php b/tests/unit/Util/TestTest.php index 7fc8a923eb6..edfc41bcfc1 100644 --- a/tests/unit/Util/TestTest.php +++ b/tests/unit/Util/TestTest.php @@ -1012,7 +1012,7 @@ public function testTestWithEmptyAnnotation(): void $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'anotherAnnotation' - ))->getProvidedData(); + ), VariousDocblockDefinedDataProvider::class)->getProvidedData(); $this->assertNull($result); } @@ -1022,7 +1022,7 @@ public function testTestWithSimpleCase(): void $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWith1' - ))->getProvidedData(); + ), VariousDocblockDefinedDataProvider::class)->getProvidedData(); $this->assertEquals([[1]], $result); } @@ -1032,7 +1032,7 @@ public function testTestWithMultiLineMultiParameterCase(): void $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWith1234' - ))->getProvidedData(); + ), VariousDocblockDefinedDataProvider::class)->getProvidedData(); $this->assertEquals([[1, 2], [3, 4]], $result); } @@ -1042,7 +1042,7 @@ public function testTestWithVariousTypes(): void $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWithABTrueNull' - ))->getProvidedData(); + ), VariousDocblockDefinedDataProvider::class)->getProvidedData(); $this->assertEquals([['ab'], [true], [null]], $result); } @@ -1052,7 +1052,7 @@ public function testTestWithAnnotationAfter(): void $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWith12AndAnotherAnnotation' - ))->getProvidedData(); + ), VariousDocblockDefinedDataProvider::class)->getProvidedData(); $this->assertEquals([[1], [2]], $result); } @@ -1062,7 +1062,7 @@ public function testTestWithSimpleTextAfter(): void $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWith12AndBlahBlah' - ))->getProvidedData(); + ), VariousDocblockDefinedDataProvider::class)->getProvidedData(); $this->assertEquals([[1], [2]], $result); } @@ -1072,7 +1072,7 @@ public function testTestWithCharacterEscape(): void $result = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWithEscapedString' - ))->getProvidedData(); + ), VariousDocblockDefinedDataProvider::class)->getProvidedData(); $this->assertEquals([['"', '"']], $result); } @@ -1082,7 +1082,7 @@ public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed(): void $docBlock = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWithMalformedValue' - )); + ), VariousDocblockDefinedDataProvider::class); $this->expectException(Exception::class); $this->expectExceptionMessageRegExp('/^The data set for the @testWith annotation cannot be parsed:/'); @@ -1095,7 +1095,7 @@ public function testTestWithThrowsProperExceptionIfMultiLineDatasetCannotBeParse $docBlock = DocBlock::ofMethod(new \ReflectionMethod( \VariousDocblockDefinedDataProvider::class, 'testWithWellFormedAndMalformedValue' - )); + ), VariousDocblockDefinedDataProvider::class); $this->expectException(Exception::class); $this->expectExceptionMessageRegExp('/^The data set for the @testWith annotation cannot be parsed:/'); From 89bfa40e9a62cc3d0372f75c98d75ece65133f2a Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 13:00:01 +0200 Subject: [PATCH 13/15] Revert "Revert "Last codestyle fix (I hope)"" This reverts commit f57f550268ef23ccb74c6b4da6f4e0cb4d515179. --- src/Framework/DataProviderTestSuite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Framework/DataProviderTestSuite.php b/src/Framework/DataProviderTestSuite.php index 0058c3fc18d..18800be56ca 100644 --- a/src/Framework/DataProviderTestSuite.php +++ b/src/Framework/DataProviderTestSuite.php @@ -56,7 +56,7 @@ public function getSize(): int { [$className, $methodName] = \explode('::', $this->getName()); - /** @psalm-suppress ArgumentTypeCoercion */ + /* @psalm-suppress ArgumentTypeCoercion */ return TestUtil::getSize($className, $methodName); } } From c70d7929ebc349345df649886e5ddd8c530423f8 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 13:03:30 +0200 Subject: [PATCH 14/15] Add ArgumentTypeCoercion to psalm baseline --- .psalm/baseline.xml | 37 +++++++++++-------------- src/Framework/DataProviderTestSuite.php | 1 - 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.psalm/baseline.xml b/.psalm/baseline.xml index aa09e72a9ed..dad972a8733 100644 --- a/.psalm/baseline.xml +++ b/.psalm/baseline.xml @@ -1,5 +1,5 @@ - + $expectedElement->childNodes->item($i) @@ -83,6 +83,11 @@ "--- Expected\n+++ Actual\n" + + + $className + + $comparisonFailure @@ -135,16 +140,6 @@ \WSDL_CACHE_NONE - - - $invocation === null - - - - - null - - $this->type @@ -159,6 +154,16 @@ allowsNull + + + $invocation === null + + + + + null + + $class_name @@ -279,11 +284,6 @@ - - - \ThisClassDoesNotExist - - Invoker @@ -421,11 +421,6 @@ - - $className - $className - $className - \array_flip($lineNumbers) diff --git a/src/Framework/DataProviderTestSuite.php b/src/Framework/DataProviderTestSuite.php index 18800be56ca..a65dc34c372 100644 --- a/src/Framework/DataProviderTestSuite.php +++ b/src/Framework/DataProviderTestSuite.php @@ -56,7 +56,6 @@ public function getSize(): int { [$className, $methodName] = \explode('::', $this->getName()); - /* @psalm-suppress ArgumentTypeCoercion */ return TestUtil::getSize($className, $methodName); } } From 649b496279368e17c1b872895483f7a5a5b1f820 Mon Sep 17 00:00:00 2001 From: Wout Gevaert Date: Mon, 7 Oct 2019 13:12:54 +0200 Subject: [PATCH 15/15] Change $class to $classInHierarchy --- src/Util/Annotation/Registry.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Util/Annotation/Registry.php b/src/Util/Annotation/Registry.php index bdf2f698a59..1ae81728a58 100644 --- a/src/Util/Annotation/Registry.php +++ b/src/Util/Annotation/Registry.php @@ -62,16 +62,16 @@ public function forClassName(string $class): DocBlock /** * @throws Exception - * @psalm-param class-string $class + * @psalm-param class-string $classInHierarchy */ - public function forMethod(string $class, string $method): DocBlock + public function forMethod(string $classInHierarchy, string $method): DocBlock { - if (isset($this->methodDocBlocks[$class][$method])) { - return $this->methodDocBlocks[$class][$method]; + if (isset($this->methodDocBlocks[$classInHierarchy][$method])) { + return $this->methodDocBlocks[$classInHierarchy][$method]; } try { - $reflection = new \ReflectionMethod($class, $method); + $reflection = new \ReflectionMethod($classInHierarchy, $method); } catch (\ReflectionException $e) { throw new Exception( $e->getMessage(), @@ -80,6 +80,6 @@ public function forMethod(string $class, string $method): DocBlock ); } - return $this->methodDocBlocks[$class][$method] = DocBlock::ofMethod($reflection, $class); + return $this->methodDocBlocks[$classInHierarchy][$method] = DocBlock::ofMethod($reflection, $classInHierarchy); } }