Skip to content

Commit b7c90b1

Browse files
committed
[TASK] Add tests for RuleSet::getRulesAssoc with $searchPattern
Part of #974.
1 parent 6a0c56d commit b7c90b1

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
@@ -1165,6 +1165,72 @@ 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+
if ($matchingPropertyNames === []) {
1186+
self::assertSame([], $result);
1187+
}
1188+
foreach ($matchingPropertyNames as $expectedMatchingPropertyName) {
1189+
self::assertContains($expectedMatchingPropertyName, \array_keys($result));
1190+
}
1191+
}
1192+
1193+
/**
1194+
* @test
1195+
*
1196+
* @param list<string> $propertyNamesToSet
1197+
* @param list<string> $matchingPropertyNames
1198+
*
1199+
* @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames
1200+
*/
1201+
public function getRulesAssocWithPatternFiltersNonMatchingRules(
1202+
array $propertyNamesToSet,
1203+
string $searchPattern,
1204+
array $matchingPropertyNames
1205+
): void {
1206+
$this->setRulesFromPropertyNames($propertyNamesToSet);
1207+
1208+
$result = $this->subject->getRulesAssoc($searchPattern);
1209+
1210+
if ($result === []) {
1211+
self::expectNotToPerformAssertions();
1212+
}
1213+
foreach ($result as $resultRule) {
1214+
// 'expected' and 'actual' are transposed here due to necessity
1215+
self::assertContains($resultRule->getRule(), $matchingPropertyNames);
1216+
}
1217+
}
1218+
1219+
/**
1220+
* @test
1221+
*/
1222+
public function getRulesAssocWithPatternOrdersRulesByPosition(): void
1223+
{
1224+
$first = (new Rule('font'))->setPosition(1, 42);
1225+
$second = (new Rule('font-family'))->setPosition(1, 64);
1226+
$third = (new Rule('font-weight'))->setPosition(55, 7);
1227+
$this->subject->setRules([$third, $second, $first]);
1228+
1229+
$result = $this->subject->getRules('font-');
1230+
1231+
self::assertSame([$first, $second, $third], \array_values($result));
1232+
}
1233+
11681234
/**
11691235
* @param list<string> $propertyNames
11701236
*/

0 commit comments

Comments
 (0)