Skip to content

Commit b961840

Browse files
authored
[TASK] Add tests for RuleSet::getRulesAssoc with $searchPattern (#1280)
Part of #974.
1 parent 6a0c56d commit b961840

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

tests/Unit/RuleSet/RuleSetTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,62 @@ public function getRulesAssocKeysRulesByPropertyName(): void
11651165
}
11661166
}
11671167

1168+
/**
1169+
* @test
1170+
*
1171+
* @param list<string> $propertyNamesToSet
1172+
* @param list<string> $matchingPropertyNames
1173+
*
1174+
* @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames
1175+
*/
1176+
public function getRulesAssocWithPatternReturnsAllMatchingPropertyNames(
1177+
array $propertyNamesToSet,
1178+
string $searchPattern,
1179+
array $matchingPropertyNames
1180+
): void {
1181+
$this->setRulesFromPropertyNames($propertyNamesToSet);
1182+
1183+
$result = $this->subject->getRulesAssoc($searchPattern);
1184+
1185+
$resultPropertyNames = \array_keys($result);
1186+
\sort($matchingPropertyNames);
1187+
\sort($resultPropertyNames);
1188+
self::assertSame($matchingPropertyNames, $resultPropertyNames);
1189+
}
1190+
1191+
/**
1192+
* @test
1193+
*
1194+
* @param list<string> $propertyNamesToSet
1195+
*
1196+
* @dataProvider providePropertyNamesAndNonMatchingSearchPattern
1197+
*/
1198+
public function getRulesAssocWithNonMatchingPatternReturnsEmptyArray(
1199+
array $propertyNamesToSet,
1200+
string $searchPattern
1201+
): void {
1202+
$this->setRulesFromPropertyNames($propertyNamesToSet);
1203+
1204+
$result = $this->subject->getRulesAssoc($searchPattern);
1205+
1206+
self::assertSame([], $result);
1207+
}
1208+
1209+
/**
1210+
* @test
1211+
*/
1212+
public function getRulesAssocWithPatternOrdersRulesByPosition(): void
1213+
{
1214+
$first = (new Rule('font'))->setPosition(1, 42);
1215+
$second = (new Rule('font-family'))->setPosition(1, 64);
1216+
$third = (new Rule('font-weight'))->setPosition(55, 7);
1217+
$this->subject->setRules([$third, $second, $first]);
1218+
1219+
$result = $this->subject->getRules('font-');
1220+
1221+
self::assertSame([$first, $second, $third], \array_values($result));
1222+
}
1223+
11681224
/**
11691225
* @param list<string> $propertyNames
11701226
*/

0 commit comments

Comments
 (0)