Skip to content

Commit

Permalink
minor #6232 Use expectNotToPerformAssertions where applicable (SpaceP…
Browse files Browse the repository at this point in the history
…ossum)

This PR was merged into the master branch.

Discussion
----------

Use expectNotToPerformAssertions where applicable

replaces #6186 as it was closed and branch deleted before merging

Commits
-------

2b03444 Use expectNotToPerformAssertions where applicable
  • Loading branch information
SpacePossum committed Jan 12, 2022
2 parents 3f7a35d + 2b03444 commit ee92352
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
27 changes: 12 additions & 15 deletions tests/AutoReview/ProjectCodeTest.php
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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!
}
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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)
);
}
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -710,7 +707,7 @@ public function testConstantsAreInUpperCase(string $className): void
$reflectionClassConstants = $rc->getReflectionConstants();

if (\count($reflectionClassConstants) < 1) {
$this->addToAssertionCount(1);
$this->expectNotToPerformAssertions();

return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/AutoReview/TransformerTest.php
Expand Up @@ -49,7 +49,7 @@ public function testTransformerPriorityIsListed(TransformerInterface $transforme
$priority = $transformer->getPriority();

if (0 === $priority) {
$this->addToAssertionCount(1);
$this->expectNotToPerformAssertions();

return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/RuleSet/RuleSetTest.php
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Test/AbstractFixerTestCase.php
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/AbstractTransformerTestCase.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit ee92352

Please sign in to comment.