diff --git a/src/Predicate/XPath.php b/src/Predicate/XPath.php index 43a34b5..4185556 100644 --- a/src/Predicate/XPath.php +++ b/src/Predicate/XPath.php @@ -23,13 +23,21 @@ class XPath * which allows you to use the prefix in the selector. * @var array */ - private array $ns; + private array $ns = []; + + public function __construct(string $selector) + { + $this->selector = $selector; + } public function getSelector(): string { return $this->selector; } + /** + * @deprecated now used __construct() + */ public function setSelector(string $selector): self { $this->selector = $selector; diff --git a/tests/Unit/FormatterTest.php b/tests/Unit/FormatterTest.php index 54ce7a3..5fc1b7b 100644 --- a/tests/Unit/FormatterTest.php +++ b/tests/Unit/FormatterTest.php @@ -50,7 +50,7 @@ public function testHttps(): void $predicate->setConfig(['path' => '/test']) ->setCaseSensitive(true) ->setExcept('expect') - ->setXPath((new XPath())->setSelector('selector')->setNs(['foo' => 'bar'])) + ->setXPath((new XPath('selector'))->setNs(['foo' => 'bar'])) ->setJsonPath((new JsonPath('selector'))); $stub = new Stub(); @@ -114,7 +114,7 @@ public function testHttp(): void $predicate->setConfig(['path' => '/test']) ->setCaseSensitive(true) ->setExcept('expect') - ->setXPath((new XPath())->setSelector('selector')->setNs(['foo' => 'bar'])) + ->setXPath((new XPath('selector'))->setNs(['foo' => 'bar'])) ->setJsonPath((new JsonPath('selector'))); $stub = new Stub(); diff --git a/tests/Unit/Predicate/XPathTest.php b/tests/Unit/Predicate/XPathTest.php index df90035..5535f17 100644 --- a/tests/Unit/Predicate/XPathTest.php +++ b/tests/Unit/Predicate/XPathTest.php @@ -12,8 +12,8 @@ class XPathTest extends TestCase public function testFill(): void { - $xPath = new XPath(); - $xPath->setSelector('selector')->setNs(['foo' => 'bar']); + $xPath = new XPath('selector'); + $xPath->setNs(['foo' => 'bar']); $this->assertNotEmpty($xPath->getNs()); $this->assertNotEmpty($xPath->getSelector()); $this->assertEquals('selector', $xPath->getSelector()); diff --git a/tests/Unit/PredicateTest.php b/tests/Unit/PredicateTest.php index 2ffad56..78552a5 100644 --- a/tests/Unit/PredicateTest.php +++ b/tests/Unit/PredicateTest.php @@ -18,7 +18,7 @@ public function testFill(): void ->setInjectJs('Inject js string') ->setCaseSensitive(true) ->setExcept('expect') - ->setXPath((new XPath())->setSelector('selector')->setNs(['foo' => 'bar'])) + ->setXPath((new XPath('selector'))->setNs(['foo' => 'bar'])) ->setJsonPath((new JsonPath('selector'))); $this->assertNotEmpty($predicate->getOperator());