Skip to content

Commit 4f80f1e

Browse files
committed
[BUGFIX] Fix the return type of Selector::isValid()
Fixes #1043 Part of #811
1 parent b561b72 commit 4f80f1e

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Please also have a look at our
3434
- Use more native type declarations and strict mode
3535
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
3636
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145,
37-
#1162, #1163, #1166)
37+
#1162, #1163, #1166, #1174)
3838
- Add visibility to all class/interface constants (#469)
3939

4040
### Deprecated

src/Property/Selector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ class Selector implements Renderable
3737
private $selector;
3838

3939
/**
40-
* @return bool
41-
*
4240
* @internal since V8.8.0
4341
*/
44-
public static function isValid(string $selector)
42+
public static function isValid(string $selector): bool
4543
{
46-
return \preg_match(static::SELECTOR_VALIDATION_RX, $selector);
44+
$numberOfMatches = \preg_match(self::SELECTOR_VALIDATION_RX, $selector);
45+
46+
return $numberOfMatches === 1;
4747
}
4848

4949
public function __construct(string $selector)

tests/Unit/Property/SelectorTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,44 @@ public function getSpecificityReturnsSpecificityOfSelectorLastProvidedViaSetSele
9898

9999
self::assertSame($expectedSpecificity, $subject->getSpecificity());
100100
}
101+
102+
/**
103+
* @test
104+
*
105+
* @dataProvider provideSelectorsAndSpecificities
106+
*/
107+
public function isValidForValidSelectorReturnsTrue(string $selector): void
108+
{
109+
self::assertTrue(Selector::isValid($selector));
110+
}
111+
112+
/**
113+
* @return array<string, array{0: string}>
114+
*/
115+
public static function provideInvalidSelectors(): array
116+
{
117+
return [
118+
// This is currently broken.
119+
// 'empty string' => [''],
120+
'percent sign' => ['%'],
121+
// This is currently broken.
122+
// 'hash only' => ['#'],
123+
// This is currently broken.
124+
// 'dot only' => ['.'],
125+
'slash' => ['/'],
126+
'less-than sign' => ['<'],
127+
// This is currently broken.
128+
// 'whitespace only' => [" \t\n\r"],
129+
];
130+
}
131+
132+
/**
133+
* @test
134+
*
135+
* @dataProvider provideInvalidSelectors
136+
*/
137+
public function isValidForInvalidSelectorReturnsFalse(string $selector): void
138+
{
139+
self::assertFalse(Selector::isValid($selector));
140+
}
101141
}

0 commit comments

Comments
 (0)