X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Fdbal%2Ftests%2FDoctrine%2FTests%2FDBAL%2FSharding%2FPoolingShardConnectionTest.php;fp=vendor%2Fdoctrine%2Fdbal%2Ftests%2FDoctrine%2FTests%2FDBAL%2FSharding%2FPoolingShardConnectionTest.php;h=59259fd81c1218d34f0409aa3cbd0321eea1f6af;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fapplication_blanche.git diff --git a/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php new file mode 100644 index 0000000..59259fd --- /dev/null +++ b/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -0,0 +1,182 @@ +. + */ + +namespace Doctrine\Tests\DBAL\Sharding; + +use Doctrine\DBAL\DriverManager; + +class PoolingShardConnectionTest extends \PHPUnit_Framework_TestCase +{ + public function testConnect() + { + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + array('id' => 2, 'memory' => true), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + + $this->assertFalse($conn->isConnected(0)); + $conn->connect(0); + $this->assertEquals(1, $conn->fetchColumn('SELECT 1')); + $this->assertTrue($conn->isConnected(0)); + + $this->assertFalse($conn->isConnected(1)); + $conn->connect(1); + $this->assertEquals(1, $conn->fetchColumn('SELECT 1')); + $this->assertTrue($conn->isConnected(1)); + + $this->assertFalse($conn->isConnected(2)); + $conn->connect(2); + $this->assertEquals(1, $conn->fetchColumn('SELECT 1')); + $this->assertTrue($conn->isConnected(2)); + + $conn->close(); + $this->assertFalse($conn->isConnected(0)); + $this->assertFalse($conn->isConnected(1)); + $this->assertFalse($conn->isConnected(2)); + } + + public function testNoGlobalServerException() + { + $this->setExpectedException('InvalidArgumentException', "Connection Parameters require 'global' and 'shards' configurations."); + + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'shards' => array( + array('id' => 1, 'memory' => true), + array('id' => 2, 'memory' => true), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + } + + public function testNoShardsServersExecption() + { + $this->setExpectedException('InvalidArgumentException', "Connection Parameters require 'global' and 'shards' configurations."); + + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + } + + public function testNoShardsChoserExecption() + { + $this->setExpectedException('InvalidArgumentException', "Missing Shard Choser configuration 'shardChoser'"); + + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + array('id' => 2, 'memory' => true), + ), + )); + } + + public function testShardChoserWrongInstance() + { + $this->setExpectedException('InvalidArgumentException', "The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); + + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + array('id' => 2, 'memory' => true), + ), + 'shardChoser' => new \stdClass, + )); + } + + public function testShardNonNumericId() + { + $this->setExpectedException('InvalidArgumentException', "Shard Id has to be a non-negative number."); + + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 'foo', 'memory' => true), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + } + + public function testShardMissingId() + { + $this->setExpectedException('InvalidArgumentException', "Missing 'id' for one configured shard. Please specificy a unique shard-id."); + + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('memory' => true), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + } + + public function testDuplicateShardId() + { + $this->setExpectedException('InvalidArgumentException', "Shard 1 is duplicated in the configuration."); + + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + array('id' => 1, 'memory' => true), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + } + + public function testSwitchShardWithOpenTransactionException() + { + $conn = DriverManager::getConnection(array( + 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'driver' => 'pdo_sqlite', + 'global' => array('memory' => true), + 'shards' => array( + array('id' => 1, 'memory' => true), + ), + 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + )); + + $conn->beginTransaction(); + + $this->setExpectedException('Doctrine\DBAL\Sharding\ShardingException', 'Cannot switch shard when transaction is active.'); + $conn->connect(1); + } +} +