|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * Copyright OpenSearch Contributors |
| 7 | + * SPDX-License-Identifier: Apache-2.0 |
| 8 | + * |
| 9 | + * Elasticsearch PHP client |
| 10 | + * |
| 11 | + * @link https://github.com/elastic/elasticsearch-php/ |
| 12 | + * @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co) |
| 13 | + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 |
| 14 | + * @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1 |
| 15 | + * |
| 16 | + * Licensed to Elasticsearch B.V under one or more agreements. |
| 17 | + * Elasticsearch B.V licenses this file to you under the Apache 2.0 License or |
| 18 | + * the GNU Lesser General Public License, Version 2.1, at your option. |
| 19 | + * See the LICENSE file in the project root for more information. |
| 20 | + */ |
| 21 | + |
| 22 | +namespace OpenSearch\Tests\Endpoints; |
| 23 | + |
| 24 | +use OpenSearch\Common\Exceptions\RuntimeException; |
| 25 | +use OpenSearch\Endpoints\Indices\RefreshSearchAnalyzers; |
| 26 | + |
| 27 | +class RefreshSearchAnalyzersTest extends \PHPUnit\Framework\TestCase |
| 28 | +{ |
| 29 | + /** @var RefreshSearchAnalyzers */ |
| 30 | + private $instance; |
| 31 | + |
| 32 | + /** |
| 33 | + * @inheritDoc |
| 34 | + */ |
| 35 | + protected function setUp(): void |
| 36 | + { |
| 37 | + // Instance |
| 38 | + $this->instance = new RefreshSearchAnalyzers(); |
| 39 | + } |
| 40 | + |
| 41 | + public function testGetURIWhenIndexAndIdAreDefined(): void |
| 42 | + { |
| 43 | + // Arrange |
| 44 | + $expected = '/_plugins/_refresh_search_analyzers/index'; |
| 45 | + |
| 46 | + $this->instance->setIndex('index'); |
| 47 | + $this->instance->setId(10); |
| 48 | + |
| 49 | + // Act |
| 50 | + $result = $this->instance->getURI(); |
| 51 | + |
| 52 | + // Assert |
| 53 | + $this->assertEquals($expected, $result); |
| 54 | + } |
| 55 | + |
| 56 | + public function testGetURIWhenIndexIsDefinedAndIdIsNotDefined(): void |
| 57 | + { |
| 58 | + // Arrange |
| 59 | + $expected = '/_plugins/_refresh_search_analyzers/index'; |
| 60 | + |
| 61 | + $this->instance->setIndex('index'); |
| 62 | + |
| 63 | + // Act |
| 64 | + $result = $this->instance->getURI(); |
| 65 | + |
| 66 | + // Assert |
| 67 | + $this->assertEquals($expected, $result); |
| 68 | + } |
| 69 | + |
| 70 | + public function testGetURIWhenIndexIsNotDefined(): void |
| 71 | + { |
| 72 | + // Arrange |
| 73 | + $expected = RuntimeException::class; |
| 74 | + $expectedMessage = 'Missing index parameter for the endpoint indices.refresh_search_analyzers'; |
| 75 | + |
| 76 | + // Assert |
| 77 | + $this->expectException($expected); |
| 78 | + $this->expectExceptionMessage($expectedMessage); |
| 79 | + |
| 80 | + // Act |
| 81 | + $this->instance->getURI(); |
| 82 | + } |
| 83 | + |
| 84 | + public function testGetMethodWhenIdIsDefined(): void |
| 85 | + { |
| 86 | + // Arrange |
| 87 | + $expected = 'POST'; |
| 88 | + |
| 89 | + $this->instance->setId(10); |
| 90 | + |
| 91 | + // Act |
| 92 | + $result = $this->instance->getMethod(); |
| 93 | + |
| 94 | + // Assert |
| 95 | + $this->assertEquals($expected, $result); |
| 96 | + } |
| 97 | + |
| 98 | + public function testGetMethodWhenIdIsNotDefined(): void |
| 99 | + { |
| 100 | + // Arrange |
| 101 | + $expected = 'POST'; |
| 102 | + |
| 103 | + // Act |
| 104 | + $result = $this->instance->getMethod(); |
| 105 | + |
| 106 | + // Assert |
| 107 | + $this->assertEquals($expected, $result); |
| 108 | + } |
| 109 | +} |
0 commit comments