From 11158650320099d762656c065d3a13a1da42e06e Mon Sep 17 00:00:00 2001 From: Lukas Jansen <33984099+lukas-jansen@users.noreply.github.com> Date: Fri, 19 May 2023 20:40:08 +0000 Subject: [PATCH] Add unit test for RefreshSearchAnalyzers endpoint Signed-off-by: Lukas Jansen --- .../Indices/RefreshSearchAnalyzers.php | 2 +- .../Endpoints/RefreshSearchAnalyzersTest.php | 109 ++++++++++++++++++ 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/Endpoints/RefreshSearchAnalyzersTest.php diff --git a/src/OpenSearch/Endpoints/Indices/RefreshSearchAnalyzers.php b/src/OpenSearch/Endpoints/Indices/RefreshSearchAnalyzers.php index 53a94bc2..8ea86074 100644 --- a/src/OpenSearch/Endpoints/Indices/RefreshSearchAnalyzers.php +++ b/src/OpenSearch/Endpoints/Indices/RefreshSearchAnalyzers.php @@ -33,7 +33,7 @@ public function getURI(): string if (isset($index)) { return "/_plugins/_refresh_search_analyzers/$index"; } - throw new RuntimeException('Missing parameter for the endpoint indices.refresh_search_analyzers'); + throw new RuntimeException('Missing index parameter for the endpoint indices.refresh_search_analyzers'); } public function getParamWhitelist(): array diff --git a/tests/Endpoints/RefreshSearchAnalyzersTest.php b/tests/Endpoints/RefreshSearchAnalyzersTest.php new file mode 100644 index 00000000..034d97ef --- /dev/null +++ b/tests/Endpoints/RefreshSearchAnalyzersTest.php @@ -0,0 +1,109 @@ +instance = new RefreshSearchAnalyzers(); + } + + public function testGetURIWhenIndexAndIdAreDefined(): void + { + // Arrange + $expected = '/_plugins/_refresh_search_analyzers/index'; + + $this->instance->setIndex('index'); + $this->instance->setId(10); + + // Act + $result = $this->instance->getURI(); + + // Assert + $this->assertEquals($expected, $result); + } + + public function testGetURIWhenIndexIsDefinedAndIdIsNotDefined(): void + { + // Arrange + $expected = '/_plugins/_refresh_search_analyzers/index'; + + $this->instance->setIndex('index'); + + // Act + $result = $this->instance->getURI(); + + // Assert + $this->assertEquals($expected, $result); + } + + public function testGetURIWhenIndexIsNotDefined(): void + { + // Arrange + $expected = RuntimeException::class; + $expectedMessage = 'Missing index parameter for the endpoint indices.refresh_search_analyzers'; + + // Assert + $this->expectException($expected); + $this->expectExceptionMessage($expectedMessage); + + // Act + $this->instance->getURI(); + } + + public function testGetMethodWhenIdIsDefined(): void + { + // Arrange + $expected = 'POST'; + + $this->instance->setId(10); + + // Act + $result = $this->instance->getMethod(); + + // Assert + $this->assertEquals($expected, $result); + } + + public function testGetMethodWhenIdIsNotDefined(): void + { + // Arrange + $expected = 'POST'; + + // Act + $result = $this->instance->getMethod(); + + // Assert + $this->assertEquals($expected, $result); + } +}