7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
16
* @package Zend_Application
17
* @subpackage UnitTests
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: DbTest.php 15764 2009-05-25 17:37:41Z alexander $
23
if (!defined('PHPUnit_MAIN_METHOD')) {
24
define('PHPUnit_MAIN_METHOD', 'Zend_Application_Resource_DbTest::main');
30
require_once dirname(__FILE__) . '/../../../TestHelper.php';
33
* Zend_Loader_Autoloader
35
require_once 'Zend/Loader/Autoloader.php';
39
* @package Zend_Application
40
* @subpackage UnitTests
41
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
42
* @license http://framework.zend.com/license/new-bsd New BSD License
44
class Zend_Application_Resource_DbTest extends PHPUnit_Framework_TestCase
46
public static function main()
48
$suite = new PHPUnit_Framework_TestSuite(__CLASS__);
49
$result = PHPUnit_TextUI_TestRunner::run($suite);
52
public function setUp()
54
// Store original autoloaders
55
$this->loaders = spl_autoload_functions();
56
if (!is_array($this->loaders)) {
57
// spl_autoload_functions does not return empty array when no
58
// autoloaders registered...
59
$this->loaders = array();
62
Zend_Loader_Autoloader::resetInstance();
63
$this->autoloader = Zend_Loader_Autoloader::getInstance();
65
$this->application = new Zend_Application('testing');
67
require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
68
$this->bootstrap = new ZfAppBootstrap($this->application);
71
public function tearDown()
73
// Restore original autoloaders
74
$loaders = spl_autoload_functions();
75
foreach ($loaders as $loader) {
76
spl_autoload_unregister($loader);
79
foreach ($this->loaders as $loader) {
80
spl_autoload_register($loader);
83
// Reset autoloader instance so it doesn't affect other tests
84
Zend_Loader_Autoloader::resetInstance();
87
public function testAdapterIsNullByDefault()
89
require_once 'Zend/Application/Resource/Db.php';
90
$resource = new Zend_Application_Resource_Db();
91
$this->assertNull($resource->getAdapter());
94
public function testDbIsNullByDefault()
96
require_once 'Zend/Application/Resource/Db.php';
97
$resource = new Zend_Application_Resource_Db();
98
$this->assertNull($resource->getDbAdapter());
101
public function testParamsAreEmptyByDefault()
103
require_once 'Zend/Application/Resource/Db.php';
104
$resource = new Zend_Application_Resource_Db();
105
$params = $resource->getParams();
106
$this->assertTrue(empty($params));
109
public function testIsDefaultTableAdapter()
111
require_once 'Zend/Application/Resource/Db.php';
112
$resource = new Zend_Application_Resource_Db();
113
$this->assertTrue($resource->isDefaultTableAdapter());
116
public function testPassingDatabaseConfigurationSetsObjectState()
118
require_once 'Zend/Application/Resource/Db.php';
120
'adapter' => 'Pdo_Sqlite',
122
'dbname' => ':memory:',
124
'isDefaultTableAdapter' => false,
126
$resource = new Zend_Application_Resource_Db($config);
127
$this->assertFalse($resource->isDefaultTableAdapter());
128
$this->assertEquals($config['adapter'], $resource->getAdapter());
129
$this->assertEquals($config['params'], $resource->getParams());
132
public function testInitShouldInitializeDbAdapter()
134
require_once 'Zend/Application/Resource/Db.php';
136
'adapter' => 'Pdo_Sqlite',
138
'dbname' => ':memory:',
140
'isDefaultTableAdapter' => false,
142
$resource = new Zend_Application_Resource_Db($config);
144
$db = $resource->getDbAdapter();
145
$this->assertTrue($db instanceof Zend_Db_Adapter_Pdo_Sqlite);
149
if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_DbTest::main') {
150
Zend_Application_Resource_DbTest::main();