|
23 | 23 |
|
24 | 24 | class PaginatorTest extends TestCase
|
25 | 25 | {
|
26 |
| - protected const DOCUMENTS = [ |
| 26 | + private const DOCUMENTS = [ |
27 | 27 | 'hits' => [
|
28 | 28 | 'total' => 8,
|
29 | 29 | 'max_score' => 1,
|
@@ -76,10 +76,13 @@ class PaginatorTest extends TestCase
|
76 | 76 | ],
|
77 | 77 | ];
|
78 | 78 |
|
| 79 | + private const OFFSET = 4; |
| 80 | + private const LIMIT = 4; |
| 81 | + |
79 | 82 | /**
|
80 | 83 | * @var PaginatorInterface
|
81 | 84 | */
|
82 |
| - protected $paginator; |
| 85 | + private $paginator; |
83 | 86 |
|
84 | 87 | public function testConstruct()
|
85 | 88 | {
|
@@ -111,6 +114,20 @@ public function testGetTotalItems()
|
111 | 114 | self::assertSame(8., $this->paginator->getTotalItems());
|
112 | 115 | }
|
113 | 116 |
|
| 117 | + public function testGetTotalItemsForElasticSearch7() |
| 118 | + { |
| 119 | + // the total in elastichsearch >= 7 is object and not integer. |
| 120 | + $documents = self::DOCUMENTS; |
| 121 | + $documents['hits']['total'] = [ |
| 122 | + 'value' => 8, |
| 123 | + 'relation' => 'eq', |
| 124 | + ]; |
| 125 | + |
| 126 | + $paginator = $this->getPaginator(static::LIMIT, static::OFFSET, $documents); |
| 127 | + |
| 128 | + self::assertSame(8., $paginator->getTotalItems()); |
| 129 | + } |
| 130 | + |
114 | 131 | public function testGetCurrentPage()
|
115 | 132 | {
|
116 | 133 | self::assertSame(2., $this->paginator->getCurrentPage());
|
@@ -149,23 +166,23 @@ function (array $document): Foo {
|
149 | 166 |
|
150 | 167 | protected function setUp(): void
|
151 | 168 | {
|
152 |
| - $this->paginator = $this->getPaginator(4, 4); |
| 169 | + $this->paginator = $this->getPaginator(); |
153 | 170 | }
|
154 | 171 |
|
155 |
| - protected function getPaginator(int $limit, int $offset) |
| 172 | + private function getPaginator(int $limit = self::OFFSET, int $offset = self::OFFSET, array $documents = self::DOCUMENTS) |
156 | 173 | {
|
157 | 174 | $denormalizerProphecy = $this->prophesize(DenormalizerInterface::class);
|
158 | 175 |
|
159 |
| - foreach (static::DOCUMENTS['hits']['hits'] as $document) { |
| 176 | + foreach ($documents['hits']['hits'] as $document) { |
160 | 177 | $denormalizerProphecy
|
161 | 178 | ->denormalize($document, Foo::class, ItemNormalizer::FORMAT, [AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => true])
|
162 | 179 | ->willReturn($this->denormalizeFoo($document['_source']));
|
163 | 180 | }
|
164 | 181 |
|
165 |
| - return new Paginator($denormalizerProphecy->reveal(), self::DOCUMENTS, Foo::class, $limit, $offset); |
| 182 | + return new Paginator($denormalizerProphecy->reveal(), $documents, Foo::class, $limit, $offset); |
166 | 183 | }
|
167 | 184 |
|
168 |
| - protected function denormalizeFoo(array $fooDocument): Foo |
| 185 | + private function denormalizeFoo(array $fooDocument): Foo |
169 | 186 | {
|
170 | 187 | $foo = new Foo();
|
171 | 188 | $foo->setName($fooDocument['name']);
|
|
0 commit comments