Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use expectNotToPerformAssertions instead of addToAssertionCount #6186

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions tests/AutoReview/ProjectCodeTest.php
Original file line number Diff line number Diff line change
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!
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -333,7 +333,7 @@ public function testThatTestClassCoversAreCorrect(string $testClassName): void

foreach ($matches as $match) {
if ($match === $class || $parentClassName === $match) {
$this->addToAssertionCount(1);
$this->expectNotToPerformAssertions();

continue;
}
Expand Down Expand Up @@ -389,7 +389,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 All @@ -399,7 +399,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo
$parameters = $method->getParameters();

if (\count($parameters) < 2) {
$this->addToAssertionCount(1); // not enough parameters to test, all good!
$this->expectNotToPerformAssertions(); // not enough parameters to test, all good!

continue;
}
Expand All @@ -420,7 +420,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo
$expected = array_filter($expected, static function ($item): bool { return false !== $item; });

if (\count($expected) < 2) {
$this->addToAssertionCount(1); // not enough parameters to test, all good!
$this->expectNotToPerformAssertions(); // not enough parameters to test, all good!

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

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

return;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/AutoReview/TransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testTransformerPriorityIsListed(TransformerInterface $transforme
$priority = $transformer->getPriority();

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

return;
}
Expand All @@ -60,7 +60,7 @@ public function testTransformerPriorityIsListed(TransformerInterface $transforme
[$first, $second] = $pair;

if ($name === $first->getName() || $name === $second->getName()) {
$this->addToAssertionCount(1);
$this->expectNotToPerformAssertions();

return;
}
Expand Down
20 changes: 2 additions & 18 deletions tests/PregTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,7 @@ public function testPatternValidation(string $pattern, ?int $expected = null, ?s
throw $ex;
}

if (null !== $expected) {
static::assertSame($expected, $actual);

return;
}

if (!$setup()) {
$this->addToAssertionCount(1);
}
static::assertSame($expected, $actual);
}

/**
Expand Down Expand Up @@ -132,15 +124,7 @@ public function testPatternsValidation(string $pattern, ?int $expected = null, ?
throw $ex;
}

if (null !== $expected) {
static::assertSame((bool) $expected, $actual);

return;
}

if (!$setup()) {
$this->addToAssertionCount(1);
}
static::assertSame((bool) $expected, $actual);
}

public function testMatchAllFailing(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/RuleSet/RuleSetTest.php
Original file line number Diff line number Diff line change
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();
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved

return;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Test/AbstractFixerTestCase.php
Original file line number Diff line number Diff line change
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();
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved

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
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved

return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/AbstractTransformerTestCase.php
Original file line number Diff line number Diff line change
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();
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved

return;
}
Expand Down