host = Utility::getHost(); $this->logger = new ArrayLogger(); } private function getClient(): Client { $client = ClientBuilder::create() ->setHosts([$this->host]) ->setLogger($this->logger) ->setSSLVerification(false); return $client->build(); } public function testLogRequestSuccessHasInfoNotEmpty() { $client = $this->getClient(); $result = $client->info(); $this->assertNotEmpty($this->getLevelOutput(LogLevel::INFO, $this->logger->output)); } public function testLogRequestSuccessHasPortInInfo() { $client = $this->getClient(); $result = $client->info(); $this->assertStringContainsString('"port"', $this->getLevelOutput(LogLevel::INFO, $this->logger->output)); } public function testLogRequestFailHasWarning() { $client = $this->getClient(); try { $result = $client->get([ 'index' => 'foo', 'id' => 'bar' ]); } catch (Missing404Exception $e) { $this->assertNotEmpty($this->getLevelOutput(LogLevel::WARNING, $this->logger->output)); } } public function testIndexCannotBeEmptyStringForDelete() { $client = $this->getClient(); $this->expectException(Missing404Exception::class); $client->delete( [ 'index' => '', 'id' => 'test' ] ); } public function testIdCannotBeEmptyStringForDelete() { $client = $this->getClient(); $this->expectException(BadRequest400Exception::class); $client->delete( [ 'index' => 'test', 'id' => '' ] ); } public function testIndexCannotBeArrayOfEmptyStringsForDelete() { $client = $this->getClient(); $this->expectException(Missing404Exception::class); $client->delete( [ 'index' => ['', '', ''], 'id' => 'test' ] ); } public function testIndexCannotBeArrayOfNullsForDelete() { $client = $this->getClient(); $this->expectException(Missing404Exception::class); $client->delete( [ 'index' => [null, null, null], 'id' => 'test' ] ); } private function getLevelOutput(string $level, array $output): string { foreach ($output as $out) { if (false !== strpos($out, $level)) { return $out; } } return ''; } }