Skip to content

Commit b0ce7af

Browse files
authored
[CLEANUP] Streamline tests for getRules with matching pattern (#1282)
Combine two tests into one, by asserting an exact set match, instead of two-way subset matches.
1 parent b961840 commit b0ce7af

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

tests/Unit/RuleSet/RuleSetTest.php

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,42 +1001,21 @@ public function getRulesWithPatternReturnsAllMatchingRules(
10011001
array $matchingPropertyNames
10021002
): void {
10031003
$rulesToSet = self::createRulesFromPropertyNames($propertyNamesToSet);
1004-
$matchingRules = \array_filter(
1005-
$rulesToSet,
1006-
static function (Rule $rule) use ($matchingPropertyNames): bool {
1007-
return \in_array($rule->getRule(), $matchingPropertyNames, true);
1008-
}
1004+
// Use `array_values` to ensure canonical numeric array, since `array_filter` does not reindex.
1005+
$matchingRules = \array_values(
1006+
\array_filter(
1007+
$rulesToSet,
1008+
static function (Rule $rule) use ($matchingPropertyNames): bool {
1009+
return \in_array($rule->getRule(), $matchingPropertyNames, true);
1010+
}
1011+
)
10091012
);
10101013
$this->subject->setRules($rulesToSet);
10111014

10121015
$result = $this->subject->getRules($searchPattern);
10131016

1014-
foreach ($matchingRules as $expectedMatchingRule) {
1015-
self::assertContains($expectedMatchingRule, $result);
1016-
}
1017-
}
1018-
1019-
/**
1020-
* @test
1021-
*
1022-
* @param list<string> $propertyNamesToSet
1023-
* @param list<string> $matchingPropertyNames
1024-
*
1025-
* @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames
1026-
*/
1027-
public function getRulesWithPatternFiltersNonMatchingRules(
1028-
array $propertyNamesToSet,
1029-
string $searchPattern,
1030-
array $matchingPropertyNames
1031-
): void {
1032-
$this->setRulesFromPropertyNames($propertyNamesToSet);
1033-
1034-
$result = $this->subject->getRules($searchPattern);
1035-
1036-
foreach ($result as $resultRule) {
1037-
// 'expected' and 'actual' are transposed here due to necessity
1038-
self::assertContains($resultRule->getRule(), $matchingPropertyNames);
1039-
}
1017+
// `Rule`s without pre-set positions are returned in the order set. This is tested separately.
1018+
self::assertSame($matchingRules, $result);
10401019
}
10411020

10421021
/**

0 commit comments

Comments
 (0)