Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Please also have a look at our
- Use more native type declarations and strict mode
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145,
#1162, #1163, #1166, #1172)
#1162, #1163, #1166, #1172, #1174)
- Add visibility to all class/interface constants (#469)

### Deprecated
Expand Down
9 changes: 5 additions & 4 deletions src/Property/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class Selector implements Renderable
private $selector;

/**
* @return bool
*
* @internal since V8.8.0
*/
public static function isValid(string $selector)
public static function isValid(string $selector): bool
{
return \preg_match(static::SELECTOR_VALIDATION_RX, $selector);
// Note: We need to use `static::` here as the constant is overridden in the `KeyframeSelector` class.
$numberOfMatches = \preg_match(static::SELECTOR_VALIDATION_RX, $selector);

return $numberOfMatches === 1;
}

public function __construct(string $selector)
Expand Down
40 changes: 40 additions & 0 deletions tests/Unit/Property/SelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,44 @@ public function getSpecificityReturnsSpecificityOfSelectorLastProvidedViaSetSele

self::assertSame($expectedSpecificity, $subject->getSpecificity());
}

/**
* @test
*
* @dataProvider provideSelectorsAndSpecificities
*/
public function isValidForValidSelectorReturnsTrue(string $selector): void
{
self::assertTrue(Selector::isValid($selector));
}

/**
* @return array<string, array{0: string}>
*/
public static function provideInvalidSelectors(): array
{
return [
// This is currently broken.
// 'empty string' => [''],
'percent sign' => ['%'],
// This is currently broken.
// 'hash only' => ['#'],
// This is currently broken.
// 'dot only' => ['.'],
'slash' => ['/'],
'less-than sign' => ['<'],
// This is currently broken.
// 'whitespace only' => [" \t\n\r"],
];
}

/**
* @test
*
* @dataProvider provideInvalidSelectors
*/
public function isValidForInvalidSelectorReturnsFalse(string $selector): void
{
self::assertFalse(Selector::isValid($selector));
}
}