Skip to content

Commit a3e77bd

Browse files
authored
Merge pull request #30 from ans-group/add-property-to-exception
Add property causing error to InvalidSearchTermException
2 parents fee70e5 + f2e2a6c commit a3e77bd

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

src/Exceptions/InvalidSearchTermException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace UKFast\Sieve\Exceptions;
44

55
use RuntimeException;
6-
use UKFast\Sieve\SearchTerm;
76

87
class InvalidSearchTermException extends RuntimeException
98
{
109
public ?array $allowedValues = [];
10+
public ?string $property = '';
1111
}

src/Filters/EnumFilter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function modifyQuery($query, SearchTerm $search)
2727
"{$search->property()} must be one of " . implode(", ", $this->allowedValues)
2828
);
2929
$exception->allowedValues = $this->allowedValues;
30+
$exception->property = $search->property();
3031
throw $exception;
3132
}
3233
}

tests/Filters/EnumFilterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function throws_exception_on_invalid_search_term()
2525
$filter->modifyQuery($query, $search);
2626
} catch (InvalidSearchTermException $e) {
2727
$this->assertEquals(['a', 'b', 'c'], $e->allowedValues);
28+
$this->assertEquals('letter', $e->property);
2829
throw $e;
2930
}
3031
}

0 commit comments

Comments
 (0)