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 @@ -170,6 +170,12 @@ private function isValidAliasCondition(Query $condition, BaseQuery $aggregation,

$values = $condition->getValues();

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

return false;
}

if (\in_array($aggregation->getMethod(), self::EXTREMA, true)) {
return $this->isValidFilter(new Query($method, $aggregation->getAttribute(), $values), $filter);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/Validator/QueryShapeHavingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public static function invalidHavingProvider(): array
[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 compared with keyed values' => [
[Query::sum('price', 'total'), Query::groupBy(['name']), Query::having([new Query(Method::GreaterThan, 'total', ['x' => 10])])],
'GreaterThan query values must be a list',
],
'alias inside a logical group compared with keyed values' => [
[Query::sum('price', 'total'), Query::groupBy(['name']), Query::having([Query::or([new Query(Method::GreaterThan, 'total', ['x' => 10]), Query::lessThan('total', 1)])])],
'GreaterThan 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