Skip to content

Commit b081210

Browse files
committed
Enforce that Selector is set/constructed with non-empty list/string
1 parent 72e6d35 commit b081210

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

src/Property/Selector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class Selector implements Renderable
5858
/ux';
5959

6060
/**
61-
* @var list<Component>
61+
* @var non-empty-list<Component>
6262
*/
63-
private $components = [];
63+
private $components;
6464

6565
/**
6666
* @internal since V8.8.0
@@ -74,7 +74,7 @@ public static function isValid(string $selector): bool
7474
}
7575

7676
/**
77-
* @param non-empty-string|list<Component> $selector
77+
* @param non-empty-string|non-empty-list<Component> $selector
7878
* Providing a string is deprecated in version 9.2 and will not work from v10.0
7979
*
8080
* @throws \UnexpectedValueException if the selector is not valid

tests/Unit/Property/SelectorTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ public static function provideInvalidSelectorsForParse(): array
200200
* @test
201201
*
202202
* @dataProvider provideInvalidSelectors
203-
* @dataProvider provideEmptyStringAsInvalidSelector
204203
* @dataProvider provideInvalidSelectorsForParse
205204
*/
206205
public function parseThrowsExceptionWithInvalidSelector(string $selector): void
@@ -334,7 +333,6 @@ public function constructorThrowsExceptionWithInvalidSelector(string $selector):
334333
* @test
335334
*
336335
* @dataProvider provideInvalidSelectors
337-
* @dataProvider provideEmptyStringAsInvalidSelector
338336
* @dataProvider provideInvalidSelectorsForParse
339337
*/
340338
public function setSelectorThrowsExceptionWithInvalidSelector(string $selector): void
@@ -395,7 +393,7 @@ public static function provideComponentsAndArrayRepresentation(): array
395393
*/
396394
public function setComponentsSetsComponentsProvided(array $components, array $expectedRepresenation): void
397395
{
398-
$subject = new Selector([]);
396+
$subject = new Selector([new CompoundSelector('p')]);
399397

400398
$subject->setComponents($components);
401399

@@ -405,26 +403,30 @@ public function setComponentsSetsComponentsProvided(array $components, array $ex
405403

406404
/**
407405
* @test
406+
*
407+
* @param non-empty-list<Component> $components
408+
*
409+
* @dataProvider provideComponentsAndArrayRepresentation
408410
*/
409-
public function getComponentsReturnsEmptyArrayIfNotSet(): void
411+
public function getComponentsReturnsComponentsProvidedToConstructor(array $components): void
410412
{
411-
$subject = new Selector([]);
413+
$subject = new Selector($components);
412414

413415
$result = $subject->getComponents();
414416

415-
self::assertSame([], $result);
417+
self::assertSame($components, $result);
416418
}
417419

418420
/**
419421
* @test
420422
*
421-
* @param list<Component> $components
423+
* @param non-empty-list<Component> $components
422424
*
423425
* @dataProvider provideComponentsAndArrayRepresentation
424426
*/
425427
public function getComponentsReturnsComponentsSet(array $components): void
426428
{
427-
$subject = new Selector([]);
429+
$subject = new Selector([new CompoundSelector('p')]);
428430
$subject->setComponents($components);
429431

430432
$result = $subject->getComponents();
@@ -541,7 +543,7 @@ public function doesNotCleanupSpacesWithinAttributeSelector(): void
541543
*/
542544
public function getArrayRepresentationIncludesClassName(): void
543545
{
544-
$subject = new Selector([]);
546+
$subject = new Selector([new CompoundSelector('p')]);
545547

546548
$result = $subject->getArrayRepresentation();
547549

0 commit comments

Comments
 (0)