|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * Copyright MacFJA |
| 7 | + * |
| 8 | + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 9 | + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the |
| 10 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | + * permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the |
| 14 | + * Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 17 | + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 18 | + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | + |
| 22 | +namespace MacFJA\RediSearch\tests\Redis\Command; |
| 23 | + |
| 24 | +use MacFJA\RediSearch\Redis\Command\Aggregate; |
| 25 | +use MacFJA\RediSearch\Redis\Command\Profile; |
| 26 | +use MacFJA\RediSearch\Redis\Command\Search; |
| 27 | +use PHPUnit\Framework\TestCase; |
| 28 | + |
| 29 | +/** |
| 30 | + * @covers \MacFJA\RediSearch\Redis\Command\AbstractCommand |
| 31 | + * |
| 32 | + * @covers \MacFJA\RediSearch\Redis\Command\Profile |
| 33 | + * @covers \MacFJA\RediSearch\Redis\Command\ProfileCommand\QueryOption |
| 34 | + * |
| 35 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\AbstractCommandOption |
| 36 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\CustomValidatorOption |
| 37 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\NamelessOption |
| 38 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\NamedOption |
| 39 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\FlagOption |
| 40 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\GroupedOption |
| 41 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\NotEmptyOption |
| 42 | + * @uses \MacFJA\RediSearch\Redis\Command\Option\NumberedOption |
| 43 | + * @uses \MacFJA\RediSearch\Redis\Command\Search |
| 44 | + * @uses \MacFJA\RediSearch\Redis\Command\Aggregate |
| 45 | + * @uses \MacFJA\RediSearch\Redis\Command\SearchCommand\GeoFilterOption |
| 46 | + * @uses \MacFJA\RediSearch\Redis\Command\SearchCommand\HighlightOption |
| 47 | + * @uses \MacFJA\RediSearch\Redis\Command\SearchCommand\LimitOption |
| 48 | + * @uses \MacFJA\RediSearch\Redis\Command\SearchCommand\SortByOption |
| 49 | + * @uses \MacFJA\RediSearch\Redis\Command\SearchCommand\SummarizeOption |
| 50 | + * @uses \MacFJA\RediSearch\Redis\Command\AggregateCommand\SortByOption |
| 51 | + * @uses \MacFJA\RediSearch\Redis\Command\AggregateCommand\WithCursor |
| 52 | + * |
| 53 | + * @internal |
| 54 | + */ |
| 55 | +class ProfileTest extends TestCase |
| 56 | +{ |
| 57 | + public function testGetId(): void |
| 58 | + { |
| 59 | + $command = new Profile(); |
| 60 | + static::assertSame('FT.PROFILE', $command->getId()); |
| 61 | + } |
| 62 | + |
| 63 | + public function testFullOption(): void |
| 64 | + { |
| 65 | + $aggregate = new Aggregate(Profile::MAX_IMPLEMENTED_VERSION); |
| 66 | + $aggregate->setQuery('@foo:bar')->setIndex('idx'); |
| 67 | + $command = new Profile(Profile::MAX_IMPLEMENTED_VERSION); |
| 68 | + $command |
| 69 | + ->setIndex('idx') |
| 70 | + ->setTypeAggregate() |
| 71 | + ->setLimited() |
| 72 | + ->setQuery($aggregate) |
| 73 | + ; |
| 74 | + |
| 75 | + static::assertSame([ |
| 76 | + 'idx', 'AGGREGATE', 'LIMITED', 'QUERY', '@foo:bar', |
| 77 | + ], $command->getArguments()); |
| 78 | + } |
| 79 | + |
| 80 | + public function testSearch(): void |
| 81 | + { |
| 82 | + $search = new Search('2.2.0'); |
| 83 | + $search->setIndex('idx')->setQuery('@foo:bar'); |
| 84 | + $command = new Profile('2.2.0'); |
| 85 | + $command |
| 86 | + ->setIndex('idx') |
| 87 | + ->setTypeSearch() |
| 88 | + ->setQuery($search) |
| 89 | + ; |
| 90 | + |
| 91 | + static::assertSame([ |
| 92 | + 'idx', 'SEARCH', 'QUERY', '@foo:bar', |
| 93 | + ], $command->getArguments()); |
| 94 | + } |
| 95 | + |
| 96 | + public function testAutoFill(): void |
| 97 | + { |
| 98 | + $search = new Search('2.2.0'); |
| 99 | + $search->setIndex('idx')->setQuery('@foo:bar'); |
| 100 | + $command = new Profile('2.2.0'); |
| 101 | + $command |
| 102 | + ->setQuery($search) |
| 103 | + ; |
| 104 | + |
| 105 | + static::assertSame([ |
| 106 | + 'idx', 'SEARCH', 'QUERY', '@foo:bar', |
| 107 | + ], $command->getArguments()); |
| 108 | + } |
| 109 | + |
| 110 | + public function testOverride(): void |
| 111 | + { |
| 112 | + $search = new Search('2.2.0'); |
| 113 | + $search->setIndex('idx')->setQuery('@foo:bar'); |
| 114 | + $command = new Profile('2.2.0'); |
| 115 | + $command |
| 116 | + ->setQuery($search) |
| 117 | + ->setIndex('idx2') |
| 118 | + ->setTypeAggregate() |
| 119 | + ; |
| 120 | + |
| 121 | + static::assertSame([ |
| 122 | + 'idx2', 'AGGREGATE', 'QUERY', '@foo:bar', |
| 123 | + ], $command->getArguments()); |
| 124 | + } |
| 125 | +} |
0 commit comments