Skip to content

Commit

Permalink
Add forgotten getter method
Browse files Browse the repository at this point in the history
Add forgotten getter method to get the DOM query that is attached to an
`InvalidDomQueryException` instance.
  • Loading branch information
otsch committed Dec 1, 2023
1 parent 4fe6f87 commit cec3475
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.3.3] - 2023-12-01
### Fixed
* Add forgotten getter method to get the DOM query that is attached to an `InvalidDomQueryException` instance.

## [1.3.2] - 2023-12-01
### Fixed
* When creating a `CssSelector` or `XPathQuery` instance with invalid selector/query syntax, an `InvalidDomQueryException` is now immediately thrown. This change is considered to be not only non-breaking, but actually a fix, because the `CssSelector` would otherwise throw an exception later when the `apply()` method is called. The `XPathQuery` would silently return no result without notifying you of the invalid query and generate a PHP warning.
Expand Down
5 changes: 5 additions & 0 deletions src/Steps/Html/Exceptions/InvalidDomQueryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public function setDomQuery(string $domQuery): void
{
$this->query = $domQuery;
}

public function getDomQuery(): string
{
return $this->query;
}
}
34 changes: 34 additions & 0 deletions tests/Steps/Html/Exceptions/InvalidDomQueryExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace tests\Steps\Html\Exceptions;

use Crwlr\Crawler\Steps\Html\Exceptions\InvalidDomQueryException;
use Symfony\Component\CssSelector\Exception\ExpressionErrorException;
use Symfony\Component\CssSelector\Exception\SyntaxErrorException;

it('can be created from a symfony ExpressionErrorException', function () {
$exception = InvalidDomQueryException::fromSymfonyException('.foo:before', new ExpressionErrorException('error'));

expect($exception->getDomQuery())
->toBe('.foo:before')
->and($exception->getMessage())
->toBe('error');
});

it('can be created from a symfony SyntaxErrorException', function () {
$exception = InvalidDomQueryException::fromSymfonyException('.foo;', new SyntaxErrorException('error message'));

expect($exception->getDomQuery())
->toBe('.foo;')
->and($exception->getMessage())
->toBe('error message');
});

it('can be created from a message and a query', function () {
$exception = InvalidDomQueryException::make('message', '.foo > .bar;');

expect($exception->getDomQuery())
->toBe('.foo > .bar;')
->and($exception->getMessage())
->toBe('message');
});

0 comments on commit cec3475

Please sign in to comment.