Skip to content

Commit

Permalink
Merge pull request #240 from ergebnis/fix/split
Browse files Browse the repository at this point in the history
Fix: Split test using data provider into separate tests
  • Loading branch information
ergebnis-bot committed Nov 1, 2020
2 parents 967d66a + 2b51f39 commit 50c1354
Showing 1 changed file with 24 additions and 34 deletions.
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

0 comments on commit 50c1354

Please sign in to comment.