diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-20 09:00:55 +0100 |
commit | a2190ac74dd4d7080b12bab90e552d7aa81209ef (patch) | |
tree | 8b31f38de9882d18df54cf8d9e0de74167a094eb /vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/ConnectionPoolTest.php | |
parent | 15e69f7b20b6596b9148030acce5b59993b95a45 (diff) | |
parent | 257401d8b2cf661adf36c84b0e3fd1cf85e33c22 (diff) |
Merge branch 'mw-1.26'
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/ConnectionPoolTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/ConnectionPoolTest.php | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/ConnectionPoolTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/ConnectionPoolTest.php new file mode 100644 index 00000000..ee03587a --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/ConnectionPoolTest.php @@ -0,0 +1,112 @@ +<?php +namespace Elastica\Test\Connection; + +use Elastica\Connection; +use Elastica\Connection\ConnectionPool; +use Elastica\Connection\Strategy\StrategyFactory; +use Elastica\Test\Base as BaseTest; + +/** + * @author chabior + */ +class ConnectionPoolTest extends BaseTest +{ + /** + * @group unit + */ + public function testConstruct() + { + $pool = $this->createPool(); + + $this->assertEquals($this->getConnections(), $pool->getConnections()); + } + + /** + * @group unit + */ + public function testSetConnections() + { + $pool = $this->createPool(); + + $connections = $this->getConnections(5); + + $pool->setConnections($connections); + + $this->assertEquals($connections, $pool->getConnections()); + + $this->assertInstanceOf('Elastica\Connection\ConnectionPool', $pool->setConnections($connections)); + } + + /** + * @group unit + */ + public function testAddConnection() + { + $pool = $this->createPool(); + $pool->setConnections(array()); + + $connections = $this->getConnections(5); + + foreach ($connections as $connection) { + $pool->addConnection($connection); + } + + $this->assertEquals($connections, $pool->getConnections()); + + $this->assertInstanceOf('Elastica\Connection\ConnectionPool', $pool->addConnection($connections[0])); + } + + /** + * @group unit + */ + public function testHasConnection() + { + $pool = $this->createPool(); + + $this->assertTrue($pool->hasConnection()); + } + + /** + * @group unit + */ + public function testFailHasConnections() + { + $pool = $this->createPool(); + + $pool->setConnections(array()); + + $this->assertFalse($pool->hasConnection()); + } + + /** + * @group unit + */ + public function testGetConnection() + { + $pool = $this->createPool(); + + $this->assertInstanceOf('Elastica\Connection', $pool->getConnection()); + } + + protected function getConnections($quantity = 1) + { + $params = array(); + $connections = array(); + + for ($i = 0; $i < $quantity; $i++) { + $connections[] = new Connection($params); + } + + return $connections; + } + + protected function createPool() + { + $connections = $this->getConnections(); + $strategy = StrategyFactory::create('Simple'); + + $pool = new ConnectionPool($connections, $strategy); + + return $pool; + } +} |