|
| 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\CreateCommand; |
| 23 | + |
| 24 | +use MacFJA\RediSearch\Exception\InvalidJSONPathException; |
| 25 | +use MacFJA\RediSearch\Redis\Command\CreateCommand\JSONFieldOption; |
| 26 | +use PHPUnit\Framework\TestCase; |
| 27 | + |
| 28 | +/** |
| 29 | + * @internal |
| 30 | + * |
| 31 | + * @covers \MacFJA\RediSearch\Exception\InvalidJSONPathException |
| 32 | + * @covers \MacFJA\RediSearch\Redis\Command\CreateCommand\JSONFieldOption |
| 33 | + */ |
| 34 | +class JSONFieldOptionTest extends TestCase |
| 35 | +{ |
| 36 | + /** |
| 37 | + * @dataProvider dataProvider |
| 38 | + */ |
| 39 | + public function testIsPathValid(string $input, bool $expected): void |
| 40 | + { |
| 41 | + static::assertEquals($expected, JSONFieldOption::isPathValid($input)); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @dataProvider dataProvider |
| 46 | + */ |
| 47 | + public function testIsPathValidException(string $input, bool $expected): void |
| 48 | + { |
| 49 | + $this->expectException(InvalidJSONPathException::class); |
| 50 | + static::assertEquals($expected, JSONFieldOption::isPathValid($input)); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @return array<string, array<bool|string>> |
| 55 | + */ |
| 56 | + public function dataProvider(string $testName): array |
| 57 | + { |
| 58 | + if ('testIsPathValid' === $testName) { |
| 59 | + return [ |
| 60 | + '2nd element of root' => ['$.[1]', true], |
| 61 | + '2nd element' => ['$[1]', true], |
| 62 | + 'multilevel' => ['$.basic.dict.new_child_1', true], |
| 63 | + 'empty 2' => [' ', false], |
| 64 | + 'empty' => ['', false], |
| 65 | + 'not close 2' => ['$[', false], |
| 66 | + 'missing dollar' => ['.basic', false], |
| 67 | + ]; |
| 68 | + } |
| 69 | + |
| 70 | + return [ |
| 71 | + 'not close 1' => ['$(', false], |
| 72 | + ]; |
| 73 | + } |
| 74 | +} |
0 commit comments