Skip to content

Commit

Permalink
Fixes #2185 Follow up on dependency lib version needed (#2186)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelkeska authored Jan 17, 2024
1 parent ad5452a commit 32a3010
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], '/') : '',
]),
];
}
Expand Down
16 changes: 0 additions & 16 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions tests/ClientConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down
58 changes: 58 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/Query/MoreLikeThisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down

0 comments on commit 32a3010

Please sign in to comment.