Skip to content

Commit 19a717f

Browse files
committed
[TASK] Add tests for RuleSet::getRulesAssoc with $searchPattern
Part of #974.
1 parent 4f1fcf3 commit 19a717f

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tests/Unit/RuleSet/RuleSetTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,72 @@ public function getRulesAssocKeysRulesByPropertyName(): void
11421142
}
11431143
}
11441144

1145+
/**
1146+
* @test
1147+
*
1148+
* @param list<string> $propertyNamesToSet
1149+
* @param list<string> $matchingPropertyNames
1150+
*
1151+
* @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames
1152+
*/
1153+
public function getRulesAssocWithPatternReturnsAllMatchingPropertyNames(
1154+
array $propertyNamesToSet,
1155+
string $searchPattern,
1156+
array $matchingPropertyNames
1157+
): void {
1158+
$this->setRulesFromPropertyNames($propertyNamesToSet);
1159+
1160+
$result = $this->subject->getRulesAssoc($searchPattern);
1161+
1162+
if ($matchingPropertyNames === []) {
1163+
self::assertSame([], $result);
1164+
}
1165+
foreach ($matchingPropertyNames as $expectedMatchingPropertyName) {
1166+
self::assertContains($expectedMatchingPropertyName, \array_keys($result));
1167+
}
1168+
}
1169+
1170+
/**
1171+
* @test
1172+
*
1173+
* @param list<string> $propertyNamesToSet
1174+
* @param list<string> $matchingPropertyNames
1175+
*
1176+
* @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames
1177+
*/
1178+
public function getRulesAssocWithPatternFiltersNonMatchingRules(
1179+
array $propertyNamesToSet,
1180+
string $searchPattern,
1181+
array $matchingPropertyNames
1182+
): void {
1183+
$this->setRulesFromPropertyNames($propertyNamesToSet);
1184+
1185+
$result = $this->subject->getRulesAssoc($searchPattern);
1186+
1187+
if ($result === []) {
1188+
self::expectNotToPerformAssertions();
1189+
}
1190+
foreach ($result as $resultRule) {
1191+
// 'expected' and 'actual' are transposed here due to necessity
1192+
self::assertContains($resultRule->getRule(), $matchingPropertyNames);
1193+
}
1194+
}
1195+
1196+
/**
1197+
* @test
1198+
*/
1199+
public function getRulesAssocWithPatternOrdersRulesByPosition(): void
1200+
{
1201+
$first = (new Rule('font'))->setPosition(1, 42);
1202+
$second = (new Rule('font-family'))->setPosition(1, 64);
1203+
$third = (new Rule('font-weight'))->setPosition(55, 7);
1204+
$this->subject->setRules([$third, $second, $first]);
1205+
1206+
$result = $this->subject->getRules('font-');
1207+
1208+
self::assertSame([$first, $second, $third], \array_values($result));
1209+
}
1210+
11451211
/**
11461212
* @param list<string> $propertyNames
11471213
*/

0 commit comments

Comments
 (0)