Skip to content

Commit

Permalink
[Tests] Add connection class tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelkeska committed Jan 17, 2024
1 parent c24304d commit 4594e0b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
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 4594e0b

Please sign in to comment.