com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
require_once 'Zend/Registry.php';
require_once 'Zend/Db/Table.php';
require_once 'Zend/Config/Ini.php';
require_once 'Users.php'; // Users: Table gateway
require_once 'User.php'; // User: Row gateway
class UsersTest extends PHPUnit_Framework_TestCase #2
{
public function __construct($name = NULL)
{
parent::__construct($name);
if(Zend_Registry::isRegistered('db')) { |#3
$this->db = Zend_Registry::get('db'); |
} else {
// load configuration information from [test] in config.ini |#4
$configFile = ROOT_DIR .'/application/config.ini'; |
$config = new Zend_Config_Ini($configFile, 'test'); |
Zend_Registry::set('config', $config); |
// set up database
$dbConfig = $config->db->config->asArray(); |#5
$db = Zend_Db::factory($config->db->adapter, $dbConfig); |
Zend_Db_Table::setDefaultAdapter($db); |
Zend_Registry::set('db', $db); |
$this->db = $db; |
}
}
}
(annotation) <#1. Setup path.>
(annotation) <#2. Class name is the same as the filename. >
(annotation) <#3. Collect database adapter from registry if it has been stored already. >
(annotation) <#4. Load test specific configuration information. >
(annotation) <#5.
Pages:
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170