|
24 | 24 | use MacFJA\RediSearch\Redis\Command\AbstractCommand;
|
25 | 25 | use MacFJA\RediSearch\Redis\Command\Search;
|
26 | 26 | use MacFJA\RediSearch\Redis\Command\SearchCommand\FilterOption;
|
| 27 | +use MacFJA\RediSearch\Redis\Response\PaginatedResponse; |
| 28 | +use MacFJA\RediSearch\Redis\Response\SearchResponseItem; |
27 | 29 | use PHPUnit\Framework\TestCase;
|
28 | 30 |
|
29 | 31 | /**
|
|
38 | 40 | *
|
39 | 41 | * @covers \MacFJA\RediSearch\Redis\Command\SearchCommand\SummarizeOption
|
40 | 42 | *
|
| 43 | + * @covers \MacFJA\RediSearch\Redis\Response\PaginatedResponse |
| 44 | + * |
41 | 45 | * @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption
|
42 | 46 | * @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption
|
43 | 47 | * @uses \MacFJA\RediSearch\Redis\Command\Option\DecoratedOptionAwareTrait
|
@@ -142,4 +146,92 @@ public function testNoSummarizeAndNoHighlight(): void
|
142 | 146 | 'LIMIT', 12, 10,
|
143 | 147 | ], $command->getArguments());
|
144 | 148 | }
|
| 149 | + |
| 150 | + public function testParsingResponseNoContent(): void |
| 151 | + { |
| 152 | + $redisResponse = [ |
| 153 | + 3, |
| 154 | + 'hash_1', |
| 155 | + 'hash_2', |
| 156 | + 'hash_3', |
| 157 | + ]; |
| 158 | + |
| 159 | + $command = new Search(AbstractCommand::MAX_IMPLEMENTED_VERSION); |
| 160 | + $command->setQuery('*'); |
| 161 | + $command->setNoContent(); |
| 162 | + |
| 163 | + $expectedResponse = new PaginatedResponse($command, 3, [ |
| 164 | + new SearchResponseItem('hash_1'), |
| 165 | + new SearchResponseItem('hash_2'), |
| 166 | + new SearchResponseItem('hash_3'), |
| 167 | + ]); |
| 168 | + |
| 169 | + $actualResponse = $command->parseResponse($redisResponse); |
| 170 | + |
| 171 | + static::assertEquals($expectedResponse, $actualResponse); |
| 172 | + } |
| 173 | + |
| 174 | + public function testParsingResponseScore(): void |
| 175 | + { |
| 176 | + $redisResponse = [ |
| 177 | + 3, |
| 178 | + 'hash_1', |
| 179 | + '0.741', |
| 180 | + ['field', '1'], |
| 181 | + 'hash_2', |
| 182 | + '0.654', |
| 183 | + ['field', '2'], |
| 184 | + 'hash_3', |
| 185 | + '0.258', |
| 186 | + ['field', '3'], |
| 187 | + ]; |
| 188 | + |
| 189 | + $command = new Search(AbstractCommand::MAX_IMPLEMENTED_VERSION); |
| 190 | + $command->setQuery('*'); |
| 191 | + $command->setWithScores(); |
| 192 | + |
| 193 | + $expectedResponse = new PaginatedResponse($command, 3, [ |
| 194 | + new SearchResponseItem('hash_1', ['field' => '1'], 0.741), |
| 195 | + new SearchResponseItem('hash_2', ['field' => '2'], 0.654), |
| 196 | + new SearchResponseItem('hash_3', ['field' => '3'], 0.258), |
| 197 | + ]); |
| 198 | + |
| 199 | + $actualResponse = $command->parseResponse($redisResponse); |
| 200 | + |
| 201 | + static::assertEquals($expectedResponse, $actualResponse); |
| 202 | + } |
| 203 | + |
| 204 | + public function testParsingResponseScoreAndPayload(): void |
| 205 | + { |
| 206 | + $redisResponse = [ |
| 207 | + 3, |
| 208 | + 'hash_1', |
| 209 | + '0.741', |
| 210 | + null, |
| 211 | + ['field', '1'], |
| 212 | + 'hash_2', |
| 213 | + '0.654', |
| 214 | + null, |
| 215 | + ['field', '2', 'other', 'field'], |
| 216 | + 'hash_3', |
| 217 | + '0.258', |
| 218 | + 'third', |
| 219 | + ['field', '3'], |
| 220 | + ]; |
| 221 | + |
| 222 | + $command = new Search(AbstractCommand::MAX_IMPLEMENTED_VERSION); |
| 223 | + $command->setQuery('*'); |
| 224 | + $command->setWithScores(); |
| 225 | + $command->setWithPayloads(); |
| 226 | + |
| 227 | + $expectedResponse = new PaginatedResponse($command, 3, [ |
| 228 | + new SearchResponseItem('hash_1', ['field' => '1'], 0.741), |
| 229 | + new SearchResponseItem('hash_2', ['field' => '2', 'other' => 'field'], 0.654), |
| 230 | + new SearchResponseItem('hash_3', ['field' => '3'], 0.258, 'third'), |
| 231 | + ]); |
| 232 | + |
| 233 | + $actualResponse = $command->parseResponse($redisResponse); |
| 234 | + |
| 235 | + static::assertEquals($expectedResponse, $actualResponse); |
| 236 | + } |
145 | 237 | }
|
0 commit comments