From cdb4bbdfc10aa40b7c91022445af8d988915242c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mantas=20Jonu=C5=A1as?= <mantas.jonusas@nfq.lt> Date: Thu, 5 Mar 2015 14:16:49 +0200 Subject: [PATCH] Exception tests moved to Unit tests --- Aggregation/DateRangeAggregationTest.php | 41 ++++++++++++++++++++++++ Aggregation/MissingAggregationTest.php | 29 +++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 Aggregation/DateRangeAggregationTest.php create mode 100644 Aggregation/MissingAggregationTest.php diff --git a/Aggregation/DateRangeAggregationTest.php b/Aggregation/DateRangeAggregationTest.php new file mode 100644 index 0000000..26081ef --- /dev/null +++ b/Aggregation/DateRangeAggregationTest.php @@ -0,0 +1,41 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Aggregation; + +use ONGR\ElasticsearchBundle\DSL\Aggregation\DateRangeAggregation; + +class DateRangeAggregationTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test if exception is thrown. + * + * @expectedException \LogicException + * @expectedExceptionMessage Date range aggregation must have field, format set and range added. + */ + public function testIfExceptionIsThrownWhenNoParametersAreSet() + { + $agg = new DateRangeAggregation('test_agg'); + $agg->getArray(); + } + + /** + * Test if exception is thrown when both range parameters are null. + * + * @expectedException \LogicException + * @expectedExceptionMessage Either from or to must be set. Both cannot be null. + */ + public function testIfExceptionIsThrownWhenBothRangesAreNull() + { + $agg = new DateRangeAggregation('test_agg'); + $agg->addRange(null, null); + } +} diff --git a/Aggregation/MissingAggregationTest.php b/Aggregation/MissingAggregationTest.php new file mode 100644 index 0000000..df8e0b1 --- /dev/null +++ b/Aggregation/MissingAggregationTest.php @@ -0,0 +1,29 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL\Aggregation; + +use ONGR\ElasticsearchBundle\DSL\Aggregation\MissingAggregation; + +class MissingAggregationTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test if exception is thrown when field is not set. + * + * @expectedException \LogicException + * @expectedExceptionMessage Missing aggregation must have a field set. + */ + public function testIfExceptionIsThrown() + { + $agg = new MissingAggregation('test_agg'); + $agg->getArray(); + } +} -- GitLab