From 2b51f395eaa1671e2895d9e64983671c4c72e277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 1 Nov 2020 19:42:08 +0100 Subject: [PATCH] Fix: Split test using data provider into separate tests --- test/Unit/RuleSet/AbstractRuleSetTestCase.php | 58 ++++++++----------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/test/Unit/RuleSet/AbstractRuleSetTestCase.php b/test/Unit/RuleSet/AbstractRuleSetTestCase.php index 6b51dccc..4943435f 100644 --- a/test/Unit/RuleSet/AbstractRuleSetTestCase.php +++ b/test/Unit/RuleSet/AbstractRuleSetTestCase.php @@ -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}> - * - * @psalm-return \Generator}> - * - * @return \Generator}> - */ - 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 *