Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Database/Validator/Query/Having.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ private function isValidLogicalCondition(Query $condition, Filter $filter): bool
$method = $condition->getMethod();
$children = $condition->getValues();

if (! \array_is_list($children)) {
$this->message = \ucfirst($method->value).' query values must be a list';

return false;
}

foreach ($children as $child) {
if (! $child instanceof Query) {
$this->message = \ucfirst($method->value).' queries can only contain filter queries';
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/Validator/QueryShapeHavingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public static function invalidHavingProvider(): array
[Query::sum('price', 'total'), Query::groupBy(['name']), Query::having([new Query(Method::And, '', ['total', Query::greaterThan('total', 10)])])],
'And queries can only contain filter queries',
],
'logical group with keyed conditions' => [
[Query::sum('price', 'total'), Query::groupBy(['name']), Query::having([new Query(Method::Or, '', ['high' => Query::greaterThan('total', 10), 'low' => Query::lessThan('total', 1)])])],
'Or query values must be a list',
],
'alias inside a logical group with an operator an aggregate cannot take' => [
[Query::sum('price', 'total'), Query::groupBy(['name']), Query::having([Query::and([Query::equal('name', ['x']), Query::startsWith('total', '1')])])],
'Aggregate alias "total" cannot be compared with startsWith',
Expand Down
Loading