From f8bfd2ad300cd137668c01dd2a42649ab0dc5046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99ska?= Date: Wed, 17 Jan 2024 11:59:43 +0100 Subject: [PATCH 1/4] [Fix] Dependency lib version elasticsearch-php --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dcd721e00..d23331d6b 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ "require": { "php": "~8.0.0 || ~8.1.0 || ~8.2.0", "ext-json": "*", - "elastic/transport": "^8.8", - "elasticsearch/elasticsearch": "^8.11", + "elastic/transport": "^8.4", + "elasticsearch/elasticsearch": "^8.4.1", "guzzlehttp/psr7": "^2.0", "nyholm/dsn": "^2.0.0", "psr/log": "^1.0 || ^2.0 || ^3.0", From 3585d4c65923801df18a70a0a752a11f100dfc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99ska?= Date: Wed, 17 Jan 2024 12:01:09 +0100 Subject: [PATCH 2/4] [Fix] Client path --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 5e4b12096..521ddaa7a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -819,7 +819,7 @@ protected function _buildTransport(array $config): Transport 'scheme' => $config['schema'] ?? 'http', 'host' => $config['host'] ?? Connection::DEFAULT_HOST, 'port' => $config['port'] ?? Connection::DEFAULT_PORT, - 'path' => isset($config['path']) ? \ltrim($config['path'], '/') : '', + 'path' => isset($config['path']) ? '/'.\ltrim($config['path'], '/') : '', ]), ]; } From c24304dd4be41481f898db2c556a1d9ded0c780e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99ska?= Date: Wed, 17 Jan 2024 12:02:00 +0100 Subject: [PATCH 3/4] [Fix] Remove unused functions --- src/Connection.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 8c243d9ec..8779e27e4 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -167,14 +167,6 @@ public function getTransportObject(): Transport return $this->getTransport(); } - /** - * @return bool Returns true if connection is persistent. True by default - */ - public function isPersistent() - { - return (bool) $this->hasParam('persistent') ? $this->getParam('persistent') : true; - } - /** * @return $this */ @@ -267,12 +259,4 @@ public function getPassword() { return $this->hasParam('password') ? $this->getParam('password') : null; } - - /** - * @return string AuthType - */ - public function getAuthType() - { - return $this->hasParam('auth_type') ? \strtolower($this->getParam('auth_type')) : null; - } } From 4594e0bb2faef7d3fb20a4e1db5dc8cdccbb75f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20K=C4=99ska?= Date: Wed, 17 Jan 2024 12:03:05 +0100 Subject: [PATCH 4/4] [Tests] Add connection class tests --- tests/ClientConfigurationTest.php | 4 +-- tests/ConnectionTest.php | 58 +++++++++++++++++++++++++++++++ tests/Query/MoreLikeThisTest.php | 2 +- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/tests/ClientConfigurationTest.php b/tests/ClientConfigurationTest.php index a648a8064..4bc6c274a 100644 --- a/tests/ClientConfigurationTest.php +++ b/tests/ClientConfigurationTest.php @@ -101,7 +101,7 @@ public function testFromEmptyArray(): void 'port' => null, 'path' => null, 'url' => null, - 'connections' => [], // host, port, path, timeout, transport, compression, persistent, timeout, username, password, config -> (curl, headers, url) + 'connections' => [], // host, port, path, timeout, transport, compression, timeout, username, password, config -> (curl, headers, url) 'roundRobin' => false, 'retryOnConflict' => 0, 'username' => null, @@ -124,7 +124,7 @@ public function testFromArray(): void 'port' => null, 'path' => null, 'url' => null, - 'connections' => [], // host, port, path, timeout, transport, compression, persistent, timeout, username, password, config -> (curl, headers, url) + 'connections' => [], // host, port, path, timeout, transport, compression, timeout, username, password, config -> (curl, headers, url) 'roundRobin' => false, 'retryOnConflict' => 0, 'username' => 'Jdoe', diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 0e8fb4a37..c4fdfb700 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -75,6 +75,13 @@ public function testGetConfig(): void $connection = new Connection(['config' => ['url' => $url]]); $this->assertTrue($connection->hasConfig('url')); $this->assertEquals($url, $connection->getConfig('url')); + + $connection->setConfig([]); + $this->assertFalse($connection->hasConfig('url')); + + $connection->addConfig('url', $url); + $this->assertTrue($connection->hasConfig('url')); + $this->assertEquals($url, $connection->getConfig('url')); } /** @@ -154,4 +161,55 @@ public function testPasswordFromClient(): void $this->assertEquals($password, $client->getConnection()->getPassword()); } + + /** + * @group unit + */ + public function testPathFromClient(): void + { + $path = 'test'; + $client = new Client(['path' => $path]); + + $this->assertEquals($path, $client->getConnection()->getPath()); + + $changedPath = 'test2'; + + $client->getConnection()->setPath($changedPath); + + $this->assertEquals($changedPath, $client->getConnection()->getPath()); + } + + /** + * @group unit + */ + public function testPortFromClient(): void + { + $port = 9000; + $client = new Client(['port' => $port]); + + $this->assertEquals($port, $client->getConnection()->getPort()); + + $changedPort = 9001; + + $client->getConnection()->setPort($changedPort); + + $this->assertEquals($changedPort, $client->getConnection()->getPort()); + } + + /** + * @group unit + */ + public function testHostFromClient(): void + { + $host = 'localhost'; + $client = new Client(['host' => $host]); + + $this->assertEquals($host, $client->getConnection()->getHost()); + + $changedHost = 'localhostChanged'; + + $client->getConnection()->setHost($changedHost); + + $this->assertEquals($changedHost, $client->getConnection()->getHost()); + } } diff --git a/tests/Query/MoreLikeThisTest.php b/tests/Query/MoreLikeThisTest.php index a19d2f7bb..e7636ae3a 100644 --- a/tests/Query/MoreLikeThisTest.php +++ b/tests/Query/MoreLikeThisTest.php @@ -65,7 +65,7 @@ public function testSearch(): void */ public function testSearchByDocument(): void { - $client = $this->_getClient(['persistent' => false]); + $client = $this->_getClient(); $index = $client->getIndex('elastica_test'); $index->create( [