From ba7a41047cea6f0f515b48c0b6b93b5308b72c5a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 1 Oct 2026 07:37:59 +0200 Subject: [PATCH 1/2] Use stricter assertions --- composer.lock | 8 ++++---- .../PHPStan/Analyser/AnalyserIntegrationTest.php | 6 +++--- tests/PHPStan/Analyser/AnalyserTest.php | 16 ++++++++-------- .../Analyser/AnalyserTraitsIntegrationTest.php | 10 +++++----- .../ConstantToFunctionParameterMapTest.php | 6 +++--- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/composer.lock b/composer.lock index bdf0173f956..06c5053c2d0 100644 --- a/composer.lock +++ b/composer.lock @@ -5167,12 +5167,12 @@ "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "ba569da0c3c4980d32e8cf26d9a0af846432191d" + "reference": "414a487e64cd63a99e16dc86963288cd6c1405eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/ba569da0c3c4980d32e8cf26d9a0af846432191d", - "reference": "ba569da0c3c4980d32e8cf26d9a0af846432191d", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/414a487e64cd63a99e16dc86963288cd6c1405eb", + "reference": "414a487e64cd63a99e16dc86963288cd6c1405eb", "shasum": "" }, "require": { @@ -5218,7 +5218,7 @@ "issues": "https://github.com/phpstan/phpstan-phpunit/issues", "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.1.x" }, - "time": "2026-09-22T19:47:21+00:00" + "time": "2026-09-30T16:47:59+00:00" }, { "name": "phpstan/phpstan-strict-rules", diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 1f60ec99d04..adc40bed1a1 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1693,20 +1693,20 @@ public function testBug14550(): void { // crash $errors = $this->runAnalyse(__DIR__ . '/data/bug-14550.php'); - $this->assertNotEmpty($errors); + $this->assertNotCount(0, $errors); } public function testBug14596(): void { // crash $errors = $this->runAnalyse(__DIR__ . '/data/bug-14596.php'); - $this->assertNotEmpty($errors); + $this->assertNotCount(0, $errors); } public function testBug9172(): void { $errors = $this->runAnalyse(__DIR__ . '/data/bug-9172.php'); - $this->assertNotEmpty($errors); + $this->assertNotCount(0, $errors); } #[RequiresPhp('>= 8.1.0')] diff --git a/tests/PHPStan/Analyser/AnalyserTest.php b/tests/PHPStan/Analyser/AnalyserTest.php index 36f53b2a7e2..e685c0d320c 100644 --- a/tests/PHPStan/Analyser/AnalyserTest.php +++ b/tests/PHPStan/Analyser/AnalyserTest.php @@ -49,31 +49,31 @@ public function testReturnErrorIfIgnoredMessagesDoesNotOccur(): void public function testDoNotReturnErrorIfIgnoredMessagesDoesNotOccurWithReportUnmatchedIgnoredErrorsOff(): void { $result = $this->runAnalyser(['#Unknown error#'], false, __DIR__ . '/data/empty/empty.php', false); - $this->assertEmpty($result); + $this->assertCount(0, $result); } public function testDoNotReturnErrorIfIgnoredMessagesDoNotOccurWhileAnalysingIndividualFiles(): void { $result = $this->runAnalyser(['#Unknown error#'], true, __DIR__ . '/data/empty/empty.php', true); - $this->assertEmpty($result); + $this->assertCount(0, $result); } public function testFileWithAnIgnoredError(): void { $result = $this->runAnalyser(['#Fail\.#'], true, __DIR__ . '/data/bootstrap-error.php', false); - $this->assertEmpty($result); + $this->assertCount(0, $result); } public function testFileWithAnIgnoredErrorMessage(): void { $result = $this->runAnalyser([['message' => '#Fail\.#']], true, __DIR__ . '/data/bootstrap-error.php', false); - $this->assertEmpty($result); + $this->assertCount(0, $result); } public function testFileWithAnIgnoredErrorRawMessage(): void { $result = $this->runAnalyser([['rawMessage' => 'Fail.']], true, __DIR__ . '/data/bootstrap-error.php', false); - $this->assertEmpty($result); + $this->assertCount(0, $result); } public function testFileWithAnIgnoredErrorMessageAndWrongIdentifier(): void @@ -109,19 +109,19 @@ public function testFileWithAnIgnoredWrongIdentifier(): void public function testFileWithAnIgnoredErrorMessageAndCorrectIdentifier(): void { $result = $this->runAnalyser([['message' => '#Fail\.#', 'identifier' => 'tests.alwaysFail']], true, __DIR__ . '/data/bootstrap-error.php', false); - $this->assertEmpty($result); + $this->assertCount(0, $result); } public function testFileWithAnIgnoredErrorRawMessageAndCorrectIdentifier(): void { $result = $this->runAnalyser([['rawMessage' => 'Fail.', 'identifier' => 'tests.alwaysFail']], true, __DIR__ . '/data/bootstrap-error.php', false); - $this->assertEmpty($result); + $this->assertCount(0, $result); } public function testFileWithAnIgnoredErrorIdentifier(): void { $result = $this->runAnalyser([['identifier' => 'tests.alwaysFail']], true, __DIR__ . '/data/bootstrap-error.php', false); - $this->assertEmpty($result); + $this->assertNotCount(0, $result); } public function testFileWithAnIgnoredErrorMessages(): void diff --git a/tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php index 1f5c87dd098..e075f803fc3 100644 --- a/tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserTraitsIntegrationTest.php @@ -32,7 +32,7 @@ public function testMethodIsInClassUsingTrait(): void __DIR__ . '/traits/Foo.php', __DIR__ . '/traits/FooTrait.php', ]); - $this->assertEmpty($errors); + $this->assertCount(0, $errors); } public function testMethodDoesNotExist(): void @@ -95,21 +95,21 @@ public function testNestedTraits(): void public function testTraitsAreNotAnalysedDirectly(): void { $errors = $this->runAnalyse([__DIR__ . '/traits/FooTrait.php']); - $this->assertEmpty($errors); + $this->assertCount(0, $errors); $errors = $this->runAnalyse([__DIR__ . '/traits/NestedFooTrait.php']); - $this->assertEmpty($errors); + $this->assertCount(0, $errors); } public function testClassAndTraitInTheSameFile(): void { $errors = $this->runAnalyse([__DIR__ . '/traits/classAndTrait.php']); - $this->assertEmpty($errors); + $this->assertCount(0, $errors); } public function testTraitMethodAlias(): void { $errors = $this->runAnalyse([__DIR__ . '/traits/trait-aliases.php']); - $this->assertEmpty($errors); + $this->assertCount(0, $errors); } public function testFindErrorsInTrait(): void diff --git a/tests/PHPStan/Reflection/ConstantToFunctionParameterMapTest.php b/tests/PHPStan/Reflection/ConstantToFunctionParameterMapTest.php index 3de062ab138..d153f52b2a7 100644 --- a/tests/PHPStan/Reflection/ConstantToFunctionParameterMapTest.php +++ b/tests/PHPStan/Reflection/ConstantToFunctionParameterMapTest.php @@ -45,7 +45,7 @@ public function testMapIsValid(): void $methodReflection = $classReflection->getNativeMethod($methodName); $variants = $methodReflection->getVariants(); - $this->assertNotEmpty($variants, sprintf('Method %s has no variants.', $entry)); + $this->assertNotCount(0, $variants, sprintf('Method %s has no variants.', $entry)); $reflectionParameters = $variants[0]->getParameters(); } else { @@ -59,7 +59,7 @@ public function testMapIsValid(): void $functionReflection = $reflectionProvider->getFunction($nameNode, null); $variants = $functionReflection->getVariants(); - $this->assertNotEmpty($variants, sprintf('Function %s() has no variants.', $entry)); + $this->assertNotCount(0, $variants, sprintf('Function %s() has no variants.', $entry)); $reflectionParameters = $variants[0]->getParameters(); } @@ -87,7 +87,7 @@ public function testMapIsValid(): void $this->assertContains($config['type'], ['single', 'bitmask'], sprintf('Invalid type "%s" for %s($%s).', $config['type'], $entry, $parameterName)); $this->assertArrayHasKey('constants', $config, sprintf('Missing "constants" key for %s($%s).', $entry, $parameterName)); $this->assertIsArray($config['constants'], sprintf('Constants for %s($%s) must be an array.', $entry, $parameterName)); - $this->assertNotEmpty($config['constants'], sprintf('Constants for %s($%s) must not be empty.', $entry, $parameterName)); + $this->assertNotCount(0, $config['constants'], sprintf('Constants for %s($%s) must not be empty.', $entry, $parameterName)); foreach ($config['constants'] as $constantName) { $this->assertIsString($constantName, sprintf('Constant name for %s($%s) must be a string.', $entry, $parameterName)); From 63e183e3dc886d447037909487c58a1b2fcb8f9a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 1 Oct 2026 07:58:42 +0200 Subject: [PATCH 2/2] Update AnalyserTest.php --- tests/PHPStan/Analyser/AnalyserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PHPStan/Analyser/AnalyserTest.php b/tests/PHPStan/Analyser/AnalyserTest.php index e685c0d320c..62bfeab01ee 100644 --- a/tests/PHPStan/Analyser/AnalyserTest.php +++ b/tests/PHPStan/Analyser/AnalyserTest.php @@ -121,7 +121,7 @@ public function testFileWithAnIgnoredErrorRawMessageAndCorrectIdentifier(): void public function testFileWithAnIgnoredErrorIdentifier(): void { $result = $this->runAnalyser([['identifier' => 'tests.alwaysFail']], true, __DIR__ . '/data/bootstrap-error.php', false); - $this->assertNotCount(0, $result); + $this->assertCount(0, $result); } public function testFileWithAnIgnoredErrorMessages(): void