diff --git a/tests/Unit/RuleSet/RuleSetTest.php b/tests/Unit/RuleSet/RuleSetTest.php index 53123466..8127efdb 100644 --- a/tests/Unit/RuleSet/RuleSetTest.php +++ b/tests/Unit/RuleSet/RuleSetTest.php @@ -1165,6 +1165,62 @@ public function getRulesAssocKeysRulesByPropertyName(): void } } + /** + * @test + * + * @param list $propertyNamesToSet + * @param list $matchingPropertyNames + * + * @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames + */ + public function getRulesAssocWithPatternReturnsAllMatchingPropertyNames( + array $propertyNamesToSet, + string $searchPattern, + array $matchingPropertyNames + ): void { + $this->setRulesFromPropertyNames($propertyNamesToSet); + + $result = $this->subject->getRulesAssoc($searchPattern); + + $resultPropertyNames = \array_keys($result); + \sort($matchingPropertyNames); + \sort($resultPropertyNames); + self::assertSame($matchingPropertyNames, $resultPropertyNames); + } + + /** + * @test + * + * @param list $propertyNamesToSet + * + * @dataProvider providePropertyNamesAndNonMatchingSearchPattern + */ + public function getRulesAssocWithNonMatchingPatternReturnsEmptyArray( + array $propertyNamesToSet, + string $searchPattern + ): void { + $this->setRulesFromPropertyNames($propertyNamesToSet); + + $result = $this->subject->getRulesAssoc($searchPattern); + + self::assertSame([], $result); + } + + /** + * @test + */ + public function getRulesAssocWithPatternOrdersRulesByPosition(): void + { + $first = (new Rule('font'))->setPosition(1, 42); + $second = (new Rule('font-family'))->setPosition(1, 64); + $third = (new Rule('font-weight'))->setPosition(55, 7); + $this->subject->setRules([$third, $second, $first]); + + $result = $this->subject->getRules('font-'); + + self::assertSame([$first, $second, $third], \array_values($result)); + } + /** * @param list $propertyNames */