-
Notifications
You must be signed in to change notification settings - Fork 149
[TASK] Add tests for RuleSet::getRulesAssoc with $searchPattern
#1280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b7c90b1
8c7419c
a32a698
fcca94e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1165,6 +1165,84 @@ public function getRulesAssocKeysRulesByPropertyName(): void | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @test | ||
| * | ||
| * @param list<string> $propertyNamesToSet | ||
| * @param list<string> $matchingPropertyNames | ||
| * | ||
| * @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames | ||
| */ | ||
| public function getRulesAssocWithPatternReturnsAllMatchingPropertyNames( | ||
| array $propertyNamesToSet, | ||
| string $searchPattern, | ||
| array $matchingPropertyNames | ||
| ): void { | ||
| $this->setRulesFromPropertyNames($propertyNamesToSet); | ||
|
|
||
| $result = $this->subject->getRulesAssoc($searchPattern); | ||
|
|
||
| foreach ($matchingPropertyNames as $expectedMatchingPropertyName) { | ||
| self::assertContains($expectedMatchingPropertyName, \array_keys($result)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @test | ||
| * | ||
| * @param list<string> $propertyNamesToSet | ||
| * @param list<string> $matchingPropertyNames | ||
| * | ||
| * @dataProvider providePropertyNamesAndSearchPatternAndMatchingPropertyNames | ||
| */ | ||
| public function getRulesAssocWithPatternFiltersNonMatchingRules( | ||
| array $propertyNamesToSet, | ||
| string $searchPattern, | ||
| array $matchingPropertyNames | ||
| ): void { | ||
| $this->setRulesFromPropertyNames($propertyNamesToSet); | ||
|
|
||
| $result = $this->subject->getRulesAssoc($searchPattern); | ||
|
|
||
| foreach ($result as $resultRule) { | ||
|
||
| // 'expected' and 'actual' are transposed here due to necessity | ||
| self::assertContains($resultRule->getRule(), $matchingPropertyNames); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @test | ||
| * | ||
| * @param list<string> $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<string> $propertyNames | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this code correctly, we can use
assertArrayHasKeyhere.https://docs.phpunit.de/en/9.6/assertions.html#assertarrayhaskey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I didn't think of that.