X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Fdbal%2Ftests%2FDoctrine%2FTests%2FDBAL%2FSharding%2FSQLAzure%2FSQLAzureShardManagerTest.php;fp=vendor%2Fdoctrine%2Fdbal%2Ftests%2FDoctrine%2FTests%2FDBAL%2FSharding%2FSQLAzure%2FSQLAzureShardManagerTest.php;h=f73e494081a9b09265c0875a01fdd5d13f115140;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fapplication_blanche.git diff --git a/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php new file mode 100644 index 0000000..f73e494 --- /dev/null +++ b/vendor/doctrine/dbal/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -0,0 +1,93 @@ +setExpectedException('Doctrine\DBAL\Sharding\ShardingException', 'SQLAzure requires a federation name to be set during sharding configuration.'); + + $conn = $this->createConnection(array('sharding' => array('distributionKey' => 'abc', 'distributionType' => 'integer'))); + $sm = new SQLAzureShardManager($conn); + } + + public function testNoDistributionKey() + { + $this->setExpectedException('Doctrine\DBAL\Sharding\ShardingException', 'SQLAzure requires a distribution key to be set during sharding configuration.'); + + $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionType' => 'integer'))); + $sm = new SQLAzureShardManager($conn); + } + + public function testNoDistributionType() + { + $this->setExpectedException('Doctrine\DBAL\Sharding\ShardingException'); + + $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo'))); + $sm = new SQLAzureShardManager($conn); + } + + public function testGetDefaultDistributionValue() + { + $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + + $sm = new SQLAzureShardManager($conn); + $this->assertNull($sm->getCurrentDistributionValue()); + } + + public function testSelectGlobalTransactionActive() + { + $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); + + $this->setExpectedException('Doctrine\DBAL\Sharding\ShardingException', 'Cannot switch shard during an active transaction.'); + + $sm = new SQLAzureShardManager($conn); + $sm->selectGlobal(); + } + + public function testSelectGlobal() + { + $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); + $conn->expects($this->at(2))->method('exec')->with($this->equalTo('USE FEDERATION ROOT WITH RESET')); + + $sm = new SQLAzureShardManager($conn); + $sm->selectGlobal(); + } + + public function testSelectShard() + { + $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); + + $this->setExpectedException('Doctrine\DBAL\Sharding\ShardingException', 'Cannot switch shard during an active transaction.'); + + $sm = new SQLAzureShardManager($conn); + $sm->selectShard(1234); + + $this->assertEquals(1234, $sm->getCurrentDistributionValue()); + } + + public function testSelectShardNoDistriubtionValue() + { + $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); + + $this->setExpectedException('Doctrine\DBAL\Sharding\ShardingException', 'You have to specify a string or integer as shard distribution value.'); + + $sm = new SQLAzureShardManager($conn); + $sm->selectShard(null); + } + + private function createConnection(array $params) + { + $conn = $this->getMock('Doctrine\DBAL\Connection', array('getParams', 'exec', 'isTransactionActive'), array(), '', false); + $conn->expects($this->at(0))->method('getParams')->will($this->returnValue($params)); + return $conn; + } +} +