From 9cac8fb279a2c02dba3f50647301cec76c3a89ca Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 27 Oct 2025 16:13:12 +0100 Subject: [PATCH 1/3] Update phpstan-phpunit to 2.0.8 --- build/phpstan.neon | 1 - composer.json | 2 +- composer.lock | 12 ++++++------ src/Type/ClosureTypeFactory.php | 2 +- tests/PHPStan/Command/CommandHelperTest.php | 2 +- .../ErrorFormatter/TeamcityErrorFormatterTest.php | 1 - .../OptimizedSingleFileSourceLocatorTest.php | 2 +- .../Reflection/ClassReflectionPropertyHooksTest.php | 7 +++++++ tests/PHPStan/Type/ClosureTypeFactoryTest.php | 4 ++-- tests/PHPStan/Type/StringTypeTest.php | 12 ++++++------ tests/PHPStan/Type/UnionTypeTest.php | 12 ++++++------ 11 files changed, 31 insertions(+), 26 deletions(-) diff --git a/build/phpstan.neon b/build/phpstan.neon index 33eb00a154..4454a9d73c 100644 --- a/build/phpstan.neon +++ b/build/phpstan.neon @@ -75,7 +75,6 @@ parameters: - '#^Dynamic call to static method PHPUnit\\Framework\\\S+\(\)\.$#' - '#should be contravariant with parameter \$node \(PhpParser\\Node\) of method PHPStan\\Rules\\Rule::processNode\(\)$#' - '#Variable property access on PhpParser\\Node#' - - '#Test::data[a-zA-Z0-9_]+\(\) return type has no value type specified in iterable type#' - identifier: shipmonk.deadMethod message: '#^Unused .*?Factory::create#' # likely used in DIC diff --git a/composer.json b/composer.json index cd308d1bff..8e4e11ea51 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "php-parallel-lint/php-parallel-lint": "^1.2.0", "phpstan/phpstan-deprecation-rules": "^2.0.2", "phpstan/phpstan-nette": "^2.0", - "phpstan/phpstan-phpunit": "^2.0.7", + "phpstan/phpstan-phpunit": "^2.0.8", "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^11.5.23", "shipmonk/composer-dependency-analyser": "^1.5", diff --git a/composer.lock b/composer.lock index c5e0f72e21..6ec07e3436 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "287b52923d083c465ffea8ba6a6441fb", + "content-hash": "7a8129b9f491fdfb4736ccea93ce4b01", "packages": [ { "name": "clue/ndjson-react", @@ -4777,17 +4777,17 @@ "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "9a9b161baee88a5f5c58d816943cff354ff233dc" + "reference": "5c89d749a03a8efc333b097407ba9f99692f589f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/9a9b161baee88a5f5c58d816943cff354ff233dc", - "reference": "9a9b161baee88a5f5c58d816943cff354ff233dc", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/5c89d749a03a8efc333b097407ba9f99692f589f", + "reference": "5c89d749a03a8efc333b097407ba9f99692f589f", "shasum": "" }, "require": { "php": "^7.4 || ^8.0", - "phpstan/phpstan": "^2.1.18" + "phpstan/phpstan": "^2.1.32" }, "conflict": { "phpunit/phpunit": "<7.0" @@ -4823,7 +4823,7 @@ "issues": "https://github.com/phpstan/phpstan-phpunit/issues", "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.x" }, - "time": "2025-07-13T11:31:46+00:00" + "time": "2025-10-27T11:04:54+00:00" }, { "name": "phpstan/phpstan-strict-rules", diff --git a/src/Type/ClosureTypeFactory.php b/src/Type/ClosureTypeFactory.php index ef4d81be75..a702909072 100644 --- a/src/Type/ClosureTypeFactory.php +++ b/src/Type/ClosureTypeFactory.php @@ -46,7 +46,7 @@ public function __construct( } /** - * @param Closure(): mixed $closure + * @param Closure(mixed): mixed $closure */ public function fromClosureObject(Closure $closure): ClosureType { diff --git a/tests/PHPStan/Command/CommandHelperTest.php b/tests/PHPStan/Command/CommandHelperTest.php index 5ecf380ddb..9b3813e054 100644 --- a/tests/PHPStan/Command/CommandHelperTest.php +++ b/tests/PHPStan/Command/CommandHelperTest.php @@ -285,7 +285,7 @@ public static function dataParameters(): array } /** - * @param array $expectedParameters + * @param array $expectedParameters * @throws InceptionNotSuccessfulException */ #[DataProvider('dataParameters')] diff --git a/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php index 488d2ebcd6..4e697459e8 100644 --- a/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php @@ -19,7 +19,6 @@ public static function dataFormatterOutputProvider(): iterable 0, 0, '', - '', ]; yield [ diff --git a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php index f8c0875f69..add5a684b7 100644 --- a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php +++ b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php @@ -235,7 +235,7 @@ public function testConstUnknown(string $constantName): void } /** - * @param class-string[] $expectedIdentifiers + * @param array $expectedIdentifiers */ #[DataProvider('dataForIdenifiersByType')] public function testLocateIdentifiersByType( diff --git a/tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php b/tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php index 80c75e06cf..3003fad564 100644 --- a/tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php +++ b/tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php @@ -2,6 +2,7 @@ namespace PHPStan\Reflection; +use PHPStan\ShouldNotHappenException; use PHPStan\Testing\PHPStanTestCase; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IntegerType; @@ -226,6 +227,9 @@ public static function dataPropertyHooks(): iterable ]; $specificFooGenerics = (new GenericObjectType('PropertyHooksTypes\\FooGenerics', [new IntegerType()]))->getClassReflection(); + if ($specificFooGenerics === null) { + throw new ShouldNotHappenException(); + } yield [ $specificFooGenerics, @@ -291,6 +295,9 @@ public static function dataPropertyHooks(): iterable ]; $specificFooGenericsConstructor = (new GenericObjectType('PropertyHooksTypes\\FooGenericsConstructor', [new IntegerType()]))->getClassReflection(); + if ($specificFooGenericsConstructor === null) { + throw new ShouldNotHappenException(); + } yield [ $specificFooGenericsConstructor, diff --git a/tests/PHPStan/Type/ClosureTypeFactoryTest.php b/tests/PHPStan/Type/ClosureTypeFactoryTest.php index 64ebdddb2f..e492febefc 100644 --- a/tests/PHPStan/Type/ClosureTypeFactoryTest.php +++ b/tests/PHPStan/Type/ClosureTypeFactoryTest.php @@ -63,7 +63,7 @@ public static function dataFromClosureObjectParameter(): array } /** - * @param Closure(): mixed $closure + * @param Closure(mixed): mixed $closure */ #[DataProvider('dataFromClosureObjectParameter')] public function testFromClosureObjectParameter(Closure $closure, int $index, string $type): void @@ -75,7 +75,7 @@ public function testFromClosureObjectParameter(Closure $closure, int $index, str } /** - * @param Closure(): mixed $closure + * @param Closure(mixed): mixed $closure */ private function getClosureType(Closure $closure): ClosureType { diff --git a/tests/PHPStan/Type/StringTypeTest.php b/tests/PHPStan/Type/StringTypeTest.php index a5630c1a30..ce9ea768b3 100644 --- a/tests/PHPStan/Type/StringTypeTest.php +++ b/tests/PHPStan/Type/StringTypeTest.php @@ -96,13 +96,13 @@ public static function dataIsSuperTypeOf(): array } #[DataProvider('dataIsSuperTypeOf')] - public function testIsSuperTypeOf(StringType $type, Type $otherType, TrinaryLogic $expectedResult): void + public function testIsSuperTypeOf(Type $stringType, Type $otherType, TrinaryLogic $expectedResult): void { - $actualResult = $type->isSuperTypeOf($otherType); + $actualResult = $stringType->isSuperTypeOf($otherType); $this->assertSame( $expectedResult->describe(), $actualResult->describe(), - sprintf('%s -> isSuperTypeOf(%s)', $type->describe(VerbosityLevel::precise()), $otherType->describe(VerbosityLevel::precise())), + sprintf('%s -> isSuperTypeOf(%s)', $stringType->describe(VerbosityLevel::precise()), $otherType->describe(VerbosityLevel::precise())), ); } @@ -174,13 +174,13 @@ public static function dataAccepts(): iterable } #[DataProvider('dataAccepts')] - public function testAccepts(StringType $type, Type $otherType, TrinaryLogic $expectedResult): void + public function testAccepts(Type $stringType, Type $otherType, TrinaryLogic $expectedResult): void { - $actualResult = $type->accepts($otherType, true)->result; + $actualResult = $stringType->accepts($otherType, true)->result; $this->assertSame( $expectedResult->describe(), $actualResult->describe(), - sprintf('%s -> accepts(%s)', $type->describe(VerbosityLevel::precise()), $otherType->describe(VerbosityLevel::precise())), + sprintf('%s -> accepts(%s)', $stringType->describe(VerbosityLevel::precise()), $otherType->describe(VerbosityLevel::precise())), ); } diff --git a/tests/PHPStan/Type/UnionTypeTest.php b/tests/PHPStan/Type/UnionTypeTest.php index d0ec27f619..fbf343319f 100644 --- a/tests/PHPStan/Type/UnionTypeTest.php +++ b/tests/PHPStan/Type/UnionTypeTest.php @@ -77,13 +77,13 @@ public static function dataIsCallable(): array } #[DataProvider('dataIsCallable')] - public function testIsCallable(UnionType $type, TrinaryLogic $expectedResult): void + public function testIsCallable(Type $unionType, TrinaryLogic $expectedResult): void { - $actualResult = $type->isCallable(); + $actualResult = $unionType->isCallable(); $this->assertSame( $expectedResult->describe(), $actualResult->describe(), - sprintf('%s -> isCallable()', $type->describe(VerbosityLevel::precise())), + sprintf('%s -> isCallable()', $unionType->describe(VerbosityLevel::precise())), ); } @@ -699,13 +699,13 @@ public static function dataIsScalar(): array } #[DataProvider('dataIsScalar')] - public function testIsScalar(UnionType $type, TrinaryLogic $expectedResult): void + public function testIsScalar(Type $unionType, TrinaryLogic $expectedResult): void { - $actualResult = $type->isScalar(); + $actualResult = $unionType->isScalar(); $this->assertSame( $expectedResult->describe(), $actualResult->describe(), - sprintf('%s -> isScalar()', $type->describe(VerbosityLevel::precise())), + sprintf('%s -> isScalar()', $unionType->describe(VerbosityLevel::precise())), ); } From 121c7c9ca735e8219563360c0721f166fbe5116a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 28 Oct 2025 07:38:24 +0100 Subject: [PATCH 2/3] assert parameter types --- tests/PHPStan/Type/StringTypeTest.php | 4 ++++ tests/PHPStan/Type/UnionTypeTest.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/PHPStan/Type/StringTypeTest.php b/tests/PHPStan/Type/StringTypeTest.php index ce9ea768b3..3be9e03240 100644 --- a/tests/PHPStan/Type/StringTypeTest.php +++ b/tests/PHPStan/Type/StringTypeTest.php @@ -98,6 +98,8 @@ public static function dataIsSuperTypeOf(): array #[DataProvider('dataIsSuperTypeOf')] public function testIsSuperTypeOf(Type $stringType, Type $otherType, TrinaryLogic $expectedResult): void { + $this->assertInstanceOf(StringType::class, $stringType); + $actualResult = $stringType->isSuperTypeOf($otherType); $this->assertSame( $expectedResult->describe(), @@ -176,6 +178,8 @@ public static function dataAccepts(): iterable #[DataProvider('dataAccepts')] public function testAccepts(Type $stringType, Type $otherType, TrinaryLogic $expectedResult): void { + $this->assertInstanceOf(StringType::class, $stringType); + $actualResult = $stringType->accepts($otherType, true)->result; $this->assertSame( $expectedResult->describe(), diff --git a/tests/PHPStan/Type/UnionTypeTest.php b/tests/PHPStan/Type/UnionTypeTest.php index fbf343319f..f140f4ccfe 100644 --- a/tests/PHPStan/Type/UnionTypeTest.php +++ b/tests/PHPStan/Type/UnionTypeTest.php @@ -79,6 +79,8 @@ public static function dataIsCallable(): array #[DataProvider('dataIsCallable')] public function testIsCallable(Type $unionType, TrinaryLogic $expectedResult): void { + $this->assertInstanceOf(UnionType::class, $unionType); + $actualResult = $unionType->isCallable(); $this->assertSame( $expectedResult->describe(), @@ -701,6 +703,8 @@ public static function dataIsScalar(): array #[DataProvider('dataIsScalar')] public function testIsScalar(Type $unionType, TrinaryLogic $expectedResult): void { + $this->assertInstanceOf(UnionType::class, $unionType); + $actualResult = $unionType->isScalar(); $this->assertSame( $expectedResult->describe(), From 21264770b5d0d64581f2b238d10d91ab49f3d940 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 29 Oct 2025 09:38:27 +0100 Subject: [PATCH 3/3] Update composer.lock --- composer.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.lock b/composer.lock index 6ec07e3436..2ae210b81f 100644 --- a/composer.lock +++ b/composer.lock @@ -4777,12 +4777,12 @@ "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "5c89d749a03a8efc333b097407ba9f99692f589f" + "reference": "033f6906f7abc5acbe3c81b642ad9e363e1bb4a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/5c89d749a03a8efc333b097407ba9f99692f589f", - "reference": "5c89d749a03a8efc333b097407ba9f99692f589f", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/033f6906f7abc5acbe3c81b642ad9e363e1bb4a0", + "reference": "033f6906f7abc5acbe3c81b642ad9e363e1bb4a0", "shasum": "" }, "require": { @@ -4823,7 +4823,7 @@ "issues": "https://github.com/phpstan/phpstan-phpunit/issues", "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.x" }, - "time": "2025-10-27T11:04:54+00:00" + "time": "2025-10-29T08:37:09+00:00" }, { "name": "phpstan/phpstan-strict-rules",