From 2b03444c6a7403f17950c21f49b35a338088c36c Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Wed, 12 Jan 2022 10:49:13 +0100 Subject: [PATCH] Use expectNotToPerformAssertions where applicable --- tests/AutoReview/ProjectCodeTest.php | 27 ++++++++++------------ tests/AutoReview/TransformerTest.php | 2 +- tests/RuleSet/RuleSetTest.php | 2 +- tests/Test/AbstractFixerTestCase.php | 4 ++-- tests/Test/AbstractTransformerTestCase.php | 2 +- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 29d9467aaeb..3cbb36586f9 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -229,7 +229,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo ); if ([] === $publicMethods) { - $this->addToAssertionCount(1); // no methods to test, all good! + $this->expectNotToPerformAssertions(); // no methods to test, all good! return; } @@ -261,7 +261,7 @@ public function testThatTestDataProvidersAreCorrectlyNamed(string $testClassName } if (0 === $asserts) { - $this->addToAssertionCount(1); // no data providers to test, all good! + $this->expectNotToPerformAssertions(); // no data providers to test, all good! } } @@ -281,7 +281,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo ); if ([] === $definedDataProviders) { - $this->addToAssertionCount(1); // no methods to test, all good! + $this->expectNotToPerformAssertions(); // no methods to test, all good! return; } @@ -309,7 +309,7 @@ public function testThatTestClassCoversAreCorrect(string $testClassName): void $reflectionClass = new \ReflectionClass($testClassName); if ($reflectionClass->isAbstract() || $reflectionClass->isInterface()) { - $this->addToAssertionCount(1); + $this->expectNotToPerformAssertions(); return; } @@ -318,7 +318,7 @@ public function testThatTestClassCoversAreCorrect(string $testClassName): void static::assertNotFalse($doc); if (1 === Preg::match('/@coversNothing/', $doc, $matches)) { - $this->addToAssertionCount(1); + $this->expectNotToPerformAssertions(); return; } @@ -332,13 +332,10 @@ public function testThatTestClassCoversAreCorrect(string $testClassName): void $parentClassName = false === $parentClass ? null : '\\'.$parentClass->getName(); foreach ($matches as $match) { - if ($match === $class || $parentClassName === $match) { - $this->addToAssertionCount(1); - - continue; - } - - static::fail(sprintf('Unexpected @covers "%s" for "%s".', $match, $testClassName)); + static::assertTrue( + $match === $class || $parentClassName === $match, + sprintf('Unexpected @covers "%s" for "%s".', $match, $testClassName) + ); } } @@ -389,7 +386,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo ); if ([] === $publicMethods) { - $this->addToAssertionCount(1); // no methods to test, all good! + $this->expectNotToPerformAssertions(); // no methods to test, all good! return; } @@ -493,7 +490,7 @@ public function testAllCodeContainSingleClassy(string $className): void public function testThereIsNoTriggerErrorUsedDirectly(string $className): void { if (Utils::class === $className) { - $this->addToAssertionCount(1); // This is where "trigger_error" should be + $this->expectNotToPerformAssertions(); // This is where "trigger_error" should be return; } @@ -710,7 +707,7 @@ public function testConstantsAreInUpperCase(string $className): void $reflectionClassConstants = $rc->getReflectionConstants(); if (\count($reflectionClassConstants) < 1) { - $this->addToAssertionCount(1); + $this->expectNotToPerformAssertions(); return; } diff --git a/tests/AutoReview/TransformerTest.php b/tests/AutoReview/TransformerTest.php index bab5ff1eaee..3bb31dd33dc 100644 --- a/tests/AutoReview/TransformerTest.php +++ b/tests/AutoReview/TransformerTest.php @@ -49,7 +49,7 @@ public function testTransformerPriorityIsListed(TransformerInterface $transforme $priority = $transformer->getPriority(); if (0 === $priority) { - $this->addToAssertionCount(1); + $this->expectNotToPerformAssertions(); return; } diff --git a/tests/RuleSet/RuleSetTest.php b/tests/RuleSet/RuleSetTest.php index 98069e661d4..dfded591cad 100644 --- a/tests/RuleSet/RuleSetTest.php +++ b/tests/RuleSet/RuleSetTest.php @@ -79,7 +79,7 @@ public function testThatDefaultConfigIsNotPassed(string $setName, string $ruleNa $fixer = current($factory->getFixers()); if (!$fixer instanceof ConfigurableFixerInterface || \is_bool($ruleConfig)) { - $this->addToAssertionCount(1); + $this->expectNotToPerformAssertions(); return; } diff --git a/tests/Test/AbstractFixerTestCase.php b/tests/Test/AbstractFixerTestCase.php index f6ab10b4199..9755de0b3f7 100644 --- a/tests/Test/AbstractFixerTestCase.php +++ b/tests/Test/AbstractFixerTestCase.php @@ -248,7 +248,7 @@ public function testFixerUseInsertSlicesWhenOnlyInsertionsArePerformed(): void // if there is no `insertAt`, it's not a candidate if (!\in_array('insertAt', $usedMethods, true)) { - $this->addToAssertionCount(1); + $this->expectNotToPerformAssertions(); return; } @@ -310,7 +310,7 @@ public function testFixerUseInsertSlicesWhenOnlyInsertionsArePerformed(): void final public function testFixerConfigurationDefinitions(): void { if (!$this->fixer instanceof ConfigurableFixerInterface) { - $this->addToAssertionCount(1); // not applied to the fixer without configuration + $this->expectNotToPerformAssertions(); // not applied to the fixer without configuration return; } diff --git a/tests/Test/AbstractTransformerTestCase.php b/tests/Test/AbstractTransformerTestCase.php index 7506d097896..2a7362baec7 100644 --- a/tests/Test/AbstractTransformerTestCase.php +++ b/tests/Test/AbstractTransformerTestCase.php @@ -92,7 +92,7 @@ public function testTransformersIsFinal(): void public function testTransformDoesNotChangeSimpleCode(): void { if (\PHP_VERSION_ID < $this->transformer->getRequiredPhpVersionId()) { - $this->addToAssertionCount(1); + $this->expectNotToPerformAssertions(); return; }