2016-12-30 06:21:17 +01:00
|
|
|
<?php
|
2016-09-14 16:27:39 +02:00
|
|
|
|
|
|
|
namespace Amp\Postgres\Test;
|
|
|
|
|
|
|
|
use Amp\Postgres\ConnectionPool;
|
2017-06-21 05:17:53 +02:00
|
|
|
use Amp\Promise;
|
|
|
|
use Amp\Success;
|
2016-09-14 16:27:39 +02:00
|
|
|
|
2016-09-20 07:47:16 +02:00
|
|
|
class ConnectionPoolTest extends AbstractPoolTest {
|
2016-09-14 16:27:39 +02:00
|
|
|
/**
|
|
|
|
* @param array $connections
|
|
|
|
*
|
|
|
|
* @return \Amp\Postgres\Pool
|
|
|
|
*/
|
|
|
|
protected function createPool(array $connections) {
|
|
|
|
$mock = $this->getMockBuilder(ConnectionPool::class)
|
|
|
|
->setConstructorArgs(['connection string', \count($connections)])
|
|
|
|
->setMethods(['createConnection'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$mock->method('createConnection')
|
2016-11-15 18:06:21 +01:00
|
|
|
->will($this->returnCallback(function () use ($connections): Promise {
|
2016-09-14 16:27:39 +02:00
|
|
|
static $count = 0;
|
|
|
|
return new Success($connections[$count++]);
|
|
|
|
}));
|
|
|
|
|
|
|
|
return $mock;
|
|
|
|
}
|
2017-06-05 06:42:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Error
|
|
|
|
* @expectedExceptionMessage Pool must contain at least one connection
|
|
|
|
*/
|
|
|
|
public function testInvalidMaxConnections() {
|
|
|
|
$pool = new ConnectionPool('connection string', 0);
|
|
|
|
}
|
2016-09-14 16:27:39 +02:00
|
|
|
}
|