From d9cc24b6ed40a057c51a3b660c0be9a76c3fd696 Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Mon, 23 Jun 2025 00:29:00 +0100 Subject: [PATCH] [CLEANUP] Streamline tests for `getRules` with matching pattern Combine two tests into one, by asserting an exact set match, instead of two-way subset matches. --- tests/Unit/RuleSet/RuleSetTest.php | 41 ++++++++---------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/tests/Unit/RuleSet/RuleSetTest.php b/tests/Unit/RuleSet/RuleSetTest.php index 8127efdb..bf763a78 100644 --- a/tests/Unit/RuleSet/RuleSetTest.php +++ b/tests/Unit/RuleSet/RuleSetTest.php @@ -1001,42 +1001,21 @@ public function getRulesWithPatternReturnsAllMatchingRules( array $matchingPropertyNames ): void { $rulesToSet = self::createRulesFromPropertyNames($propertyNamesToSet); - $matchingRules = \array_filter( - $rulesToSet, - static function (Rule $rule) use ($matchingPropertyNames): bool { - return \in_array($rule->getRule(), $matchingPropertyNames, true); - } + // Use `array_values` to ensure canonical numeric array, since `array_filter` does not reindex. + $matchingRules = \array_values( + \array_filter( + $rulesToSet, + static function (Rule $rule) use ($matchingPropertyNames): bool { + return \in_array($rule->getRule(), $matchingPropertyNames, true); + } + ) ); $this->subject->setRules($rulesToSet); $result = $this->subject->getRules($searchPattern); - foreach ($matchingRules as $expectedMatchingRule) { - self::assertContains($expectedMatchingRule, $result); - } - } - - /** - * @test - * - * @param list $propertyNamesToSet - * @param list $matchingPropertyNames - * - * @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames - */ - public function getRulesWithPatternFiltersNonMatchingRules( - array $propertyNamesToSet, - string $searchPattern, - array $matchingPropertyNames - ): void { - $this->setRulesFromPropertyNames($propertyNamesToSet); - - $result = $this->subject->getRules($searchPattern); - - foreach ($result as $resultRule) { - // 'expected' and 'actual' are transposed here due to necessity - self::assertContains($resultRule->getRule(), $matchingPropertyNames); - } + // `Rule`s without pre-set positions are returned in the order set. This is tested separately. + self::assertSame($matchingRules, $result); } /**