|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the ONGR package. |
| 5 | + * |
| 6 | + * (c) NFQ Technologies UAB <info@nfq.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace ONGR\ElasticsearchBundle\Tests\Unit\Result\Aggregation; |
| 13 | + |
| 14 | +use ONGR\ElasticsearchBundle\Result\Aggregation\AggregationIterator; |
| 15 | + |
| 16 | +/** |
| 17 | + * Class AggregationIteratorTest. |
| 18 | + */ |
| 19 | +class AggregationIteratorTest extends \PHPUnit_Framework_TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * Tests countable interface implementation. |
| 23 | + */ |
| 24 | + public function testCountable() |
| 25 | + { |
| 26 | + $this->assertInstanceOf('\\Countable', new AggregationIterator([])); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Data provider for testCount. |
| 31 | + */ |
| 32 | + public function countProvider() |
| 33 | + { |
| 34 | + $cases = []; |
| 35 | + |
| 36 | + // Case #0. No data. |
| 37 | + $cases[] = [ |
| 38 | + 'data' => [], |
| 39 | + 'expectedCount' => 0, |
| 40 | + ]; |
| 41 | + |
| 42 | + // Case #2. With data. |
| 43 | + $cases[] = [ |
| 44 | + 'data' => [ |
| 45 | + [ |
| 46 | + 'key' => 'weak', |
| 47 | + 'doc_count' => 2, |
| 48 | + 'agg_test_agg_2' => [ |
| 49 | + 'buckets' => [ |
| 50 | + [ |
| 51 | + 'key' => '*-20.0', |
| 52 | + 'to' => 20.0, |
| 53 | + 'to_as_string' => '20.0', |
| 54 | + 'doc_count' => 1, |
| 55 | + ], |
| 56 | + [ |
| 57 | + 'key' => '20.0-*', |
| 58 | + 'from' => 20.0, |
| 59 | + 'from_as_string' => '20.0', |
| 60 | + 'doc_count' => 1, |
| 61 | + ], |
| 62 | + ], |
| 63 | + ], |
| 64 | + ], |
| 65 | + [ |
| 66 | + 'key' => 'solid', |
| 67 | + 'doc_count' => 1, |
| 68 | + 'agg_test_agg_2' => [ |
| 69 | + 'buckets' => [ |
| 70 | + [ |
| 71 | + 'key' => '*-20.0', |
| 72 | + 'to' => 20.0, |
| 73 | + 'to_as_string' => '20.0', |
| 74 | + 'doc_count' => 1, |
| 75 | + ], |
| 76 | + [ |
| 77 | + 'key' => '20.0-*', |
| 78 | + 'from' => 20.0, |
| 79 | + 'from_as_string' => '20.0', |
| 80 | + 'doc_count' => 0, |
| 81 | + ], |
| 82 | + ], |
| 83 | + ], |
| 84 | + ], |
| 85 | + ], |
| 86 | + 'expectedCount' => 2, |
| 87 | + ]; |
| 88 | + |
| 89 | + return $cases; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Tests counting. |
| 94 | + * |
| 95 | + * @dataProvider countProvider |
| 96 | + * |
| 97 | + * @param array $data |
| 98 | + * @param int $expectedCount |
| 99 | + */ |
| 100 | + public function testCount($data, $expectedCount) |
| 101 | + { |
| 102 | + $iterator = new AggregationIterator($data); |
| 103 | + $this->assertCount($expectedCount, $iterator); |
| 104 | + } |
| 105 | +} |
0 commit comments