diff --git a/src/Property/Selector.php b/src/Property/Selector.php index 01db122e..f95b4c48 100644 --- a/src/Property/Selector.php +++ b/src/Property/Selector.php @@ -56,7 +56,7 @@ class Selector implements Renderable /** * @var string */ - private $selector; + private $selector = ''; /** * @internal since V8.8.0 @@ -72,9 +72,12 @@ public static function isValid(string $selector): bool /** * @throws \UnexpectedValueException if the selector is not valid */ - final public function __construct(string $selector) + final public function __construct(string $selector = '') { - $this->setSelector($selector); + // Allow construction of empty object for content to be set later via a setter method. + if ($selector !== '') { + $this->setSelector($selector); + } } /** diff --git a/tests/Unit/Property/SelectorTest.php b/tests/Unit/Property/SelectorTest.php index 1e537951..86116c55 100644 --- a/tests/Unit/Property/SelectorTest.php +++ b/tests/Unit/Property/SelectorTest.php @@ -318,7 +318,17 @@ public function parseExtractsTwoCommentsFromSelector(): void /** * @test */ - public function canConstructObjectWithEmptyState(): void + public function constructsObjectWithEmptyStateWithNoArgumetProvided(): void + { + $subject = new Selector(); + + self::assertSame('', $subject->getSelector()); + } + + /** + * @test + */ + public function constructsObjectWithEmptyStateWithEmptyStringProvided(): void { $subject = new Selector('');