Skip to content
Snippets Groups Projects
Commit d18b247a authored by Mantas Jonušas's avatar Mantas Jonušas
Browse files

Added more tests, fixed query formating bug in date range aggregation

parent 1824e778
No related branches found
No related tags found
No related merge requests found
......@@ -58,16 +58,19 @@ class DateRangeAggregation extends AbstractAggregation
*/
public function addRange($from = null, $to = null)
{
if ($from === null && $to === null) {
throw new \LogicException('Missing range');
} elseif ($from === null) {
$this->ranges = [['to' => $to]];
} elseif ($to === null) {
$this->ranges = [['from' => $from]];
} else {
$this->ranges = [['from' => $from], ['to' => $to]];
$range = array_filter(
[
'from' => $from,
'to' => $to,
]
);
if (empty($range)) {
throw new \LogicException('Either from or to must be set. Both cannot be null.');
}
$this->ranges[] = $range;
return $this;
}
......@@ -80,12 +83,12 @@ class DateRangeAggregation extends AbstractAggregation
$data = [
'format' => $this->getFormat(),
'field' => $this->getField(),
'ranges' => array_values($this->ranges),
'ranges' => $this->ranges,
];
return $data;
}
throw new \LogicException('Date range aggregation must have field and format set.');
throw new \LogicException('Date range aggregation must have field, format set and range added.');
}
/**
......
......@@ -12,7 +12,6 @@
namespace ONGR\ElasticsearchBundle\DSL\Aggregation;
use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\BucketingTrait;
use Symfony\Component\Process\Exception\LogicException;
/**
* Class representing missing aggregation.
......@@ -29,7 +28,7 @@ class MissingAggregation extends AbstractAggregation
if ($this->getField()) {
return ['field' => $this->getField()];
}
throw new LogicException('Missing aggregation must have a field set');
throw new \LogicException('Missing aggregation must have a field set.');
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment