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

Fix: Split test using data provider into separate tests #240

Merged
merged 1 commit into from
Nov 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 24 additions & 34 deletions test/Unit/RuleSet/AbstractRuleSetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,59 +125,49 @@ final public function provideValidHeader(): \Generator
}
}

/**
* @dataProvider provideSourceAndRuleNames
*/
final public function testRulesAreSortedByName(string $source, array $ruleNames): void
final public function testRulesAreSortedByNameInRuleSet(): void
{
$ruleNames = \array_keys(self::createRuleSet()->rules());

$sorted = $ruleNames;

\sort($sorted);

self::assertEquals($sorted, $ruleNames, \sprintf(
'Failed asserting that the rules are sorted by name in "%s".',
$source
'Failed asserting that the rules are sorted by name in rule set "%s".',
static::className()
));
}

/**
* @dataProvider provideSourceAndRuleNames
*/
final public function testRulesDoNotContainRuleSets(string $source, array $ruleNames): void
final public function testRulesAreSortedByNameInRuleSetTest(): void
{
$ruleNames = \array_keys($this->rules);

$sorted = $ruleNames;

\sort($sorted);

self::assertEquals($sorted, $ruleNames, \sprintf(
'Failed asserting that the rules are sorted by name in rule set test "%s".',
static::class
));
}

final public function testRulesDoNotContainRuleSets(): void
{
$ruleNames = \array_keys(self::createRuleSet()->rules());

$namesOfConfiguredRuleSets = \array_filter($ruleNames, static function (string $ruleName): bool {
return '@' === \mb_substr($ruleName, 0, 1);
});

self::assertEmpty($namesOfConfiguredRuleSets, \sprintf(
"Failed asserting that rule sets \n\n%s\n\nare not configured in \"%s\".",
"Failed asserting that rule sets \n\n%s\n\nare not configured in rule set \"%s\".",
' - ' . \implode("\n - ", $namesOfConfiguredRuleSets),
$source
static::className()
));
}

/**
* @phpstan-return \Generator<int, array{0: class-string, 1: array<string>}>
*
* @psalm-return \Generator<int, array{0: class-string, 1: array<string>}>
*
* @return \Generator<int, array{0: string, 1: array<string>}>
*/
final public function provideSourceAndRuleNames(): \Generator
{
$values = [
static::className() => self::createRuleSet()->rules(),
static::class => $this->rules,
];

foreach ($values as $source => $rules) {
yield [
$source,
\array_keys($rules),
];
}
}

/**
* @phpstan-return class-string
*
Expand Down