Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add unitTest

  • Loading branch information...
commit 657c5b852246c745e5a5153df4145f81319208f1 1 parent 18e02a9
@ClemensSahs authored
Showing with 152 additions and 0 deletions.
  1. +152 −0 tests/ZendTest/Mvc/Service/DbAdapterManagerTest.php
View
152 tests/ZendTest/Mvc/Service/DbAdapterManagerTest.php
@@ -0,0 +1,152 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @package Zend_Mvc
+ */
+
+namespace ZendTest\Mvc\Service;
+
+use PHPUnit_Framework_TestCase as TestCase;
+
+use Zend\Mvc\Service\DbAdapterManager;
+use Zend\Mvc\Service\Exception\DbAdapterManagerAdapterAllreadyRegistered;
+
+class DbAdapterManagerTest extends TestCase
+{
+ public $sampleConfig = null;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $mockPlatform = null;
+
+ public function setUp()
+ {
+ $this->mockPlatform = $this->getMock('Zend\Db\Adapter\Platform\PlatformInterface');
+
+
+ $this->sampleConfig = array(
+ 'sqlliteDb'=>array(
+ 'driver'=>array(
+ 'driver'=>'Pdo_Sqlite'
+ ),
+ 'platform'=>$this->mockPlatform
+ ),
+ 'mysqliDb'=>array(
+ 'driver'=>array(
+ 'driver'=>'Mysqli'
+ ),
+ 'platform'=>$this->mockPlatform
+ ),
+ 'sqlliteDb2'=>'sqlliteDb',
+ 'sqlliteDb3'=>'sqlliteDb2',
+ 'wrongAliase'=>'dev_null',
+ 'wrongConfig'=>array(
+ 'driver'=>array()
+ ),
+ );
+
+ }
+
+ public function testAddAdapterConfig()
+ {
+ $dam = new DbAdapterManager();
+ $dam->addDbAdapterConfig( $this->sampleConfig );
+
+ foreach ( array_keys($this->sampleConfig) as $dbKey ) {
+ $this->assertTrue( $dam->hasAdapterConfig($dbKey) );
+ }
+ }
+
+ public function testAddAdapter()
+ {
+ $dam = new DbAdapterManager();
+ $dam->addDbAdapterConfig( $this->sampleConfig );
+
+ if (extension_loaded('pdo')) {
+ $adapter = $dam->getAdapter('sqlliteDb');
+
+ $dam->addAdapter('sqlliteDb_new', $adapter);
+
+ $this->assertTrue( $dam->hasAdapter('sqlliteDb_new') );
+ $this->assertSame( $dam->getAdapter('sqlliteDb_new'), $dam->getAdapter('sqlliteDb') );
+ unset($adapter);
+ }
+ }
+
+ public function testInitDbAdapter()
+ {
+ $dam = new DbAdapterManager();
+ $dam->addDbAdapterConfig( $this->sampleConfig );
+
+ if (extension_loaded('pdo')) {
+ $adapter = $dam->getAdapter('sqlliteDb');
+ $this->assertInstanceOf('Zend\Db\Adapter\Driver\Pdo\Pdo', $adapter->driver);
+
+ $this->assertTrue( $dam->hasAdapter('sqlliteDb') );
+ unset($adapter);
+ }
+
+ if (extension_loaded('mysqli')) {
+ $adapter = $dam->getAdapter('mysqliDb');
+ $this->assertInstanceOf('Zend\Db\Adapter\Driver\Mysqli\Mysqli', $adapter->driver);
+
+ $this->assertTrue( $dam->hasAdapter('mysqliDb') );
+ unset($adapter);
+ }
+ }
+
+ public function testInitDbAdapterAliase()
+ {
+ $dam = new DbAdapterManager();
+ $dam->addDbAdapterConfig( $this->sampleConfig );
+
+ if (extension_loaded('pdo')) {
+ $adapter1 = $dam->getAdapter('sqlliteDb');
+ $adapter2 = $dam->getAdapter('sqlliteDb2');
+ $adapter3 = $dam->getAdapter('sqlliteDb3');
+
+ $this->assertSame($adapter1, $adapter2);
+ $this->assertSame($adapter1, $adapter3);
+ unset($adapter);
+ }
+ }
+
+ /**
+ * @expectedException DbAdapterManagerAdapterNotExist
+ */
+ public function testWrongAliase()
+ {
+ $dam = new DbAdapterManager();
+ $dam->addDbAdapterConfig( $this->sampleConfig );
+
+ $dam->getAdapter( 'wrongAliase' );
+ }
+
+ /**
+ * @expectedException DbAdapterManagerAdapterCoundInit
+ */
+ public function testWrongConfig()
+ {
+ $dam = new DbAdapterManager();
+ $dam->addDbAdapterConfig( $this->sampleConfig );
+
+ $dam->getAdapter( 'wrongConfig' );
+ }
+
+ /**
+ * @expectedException DbAdapterManagerAdapterAllreadyRegistered
+ */
+ public function testAdapterDuplicatKey()
+ {
+ $dam = new DbAdapterManager();
+ $dam->addDbAdapterConfig( $this->sampleConfig );
+
+ $adapter = $dam->getAdapter('sqlliteDb');
+ $dam->getAdapter('sqlliteDb',$adapter);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.