Skip to content

Commit

Permalink
Required selector for XPath
Browse files Browse the repository at this point in the history
  • Loading branch information
demyan112rv committed Aug 29, 2023
1 parent 1c72a20 commit a9852ad
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/Predicate/XPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ class XPath
* which allows you to use the prefix in the selector.
* @var array<string, string>
*/
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;
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Predicate/XPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/PredicateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit a9852ad

Please sign in to comment.