Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL | E_STRICT);
- ini_set('display_errors', 1);
- $paths = array(
- '/var/www/zf-trunk/library',
- '/var/www/test/library'
- );
- set_include_path(implode(PATH_SEPARATOR, $paths));
- require_once 'Zend/Loader/Autoloader.php';
- Zend_Loader_Autoloader::getInstance();
- $db = null;
- $cache = null;
- _setupDb();
- _dropTable();
- _createTable();
- _setupCache();
- _compareCache();
- _dropTable();
- function _setupDb()
- {
- global $db;
- $config = array(
- 'dbname' => 'zf_test',
- 'username' => 'root',
- 'password' => '',
- 'host' => '127.0.0.1',
- 'port' => '3306'
- );
- $db = Zend_Db::factory('Pdo_Mysql', $config);
- Zend_Db_Table::setDefaultAdapter($db);
- }
- function _setupCache()
- {
- global $cache;
- $cache = Zend_Cache::factory('Core', 'File', array('automatic_serialization' => true));
- $cache->clean();
- Zend_Db_Table::setDefaultMetadataCache($cache);
- }
- function _createTable()
- {
- global $db;
- $db->query('DROP TABLE IF EXISTS products');
- $sql = <<<SQL
- CREATE TABLE products (
- product_id INTEGER NOT NULL PRIMARY KEY,
- product_name VARCHAR(100)
- );
- SQL;
- $db->query($sql);
- }
- function _compareIdCache()
- {
- global $db, $cache;
- $table = new Zend_Db_Table('products');
- $table->info(Zend_Db_Table::METADATA);
- $dbConfig = $db->getConfig();
- $idCacheExpected = md5( // port:host/dbname:schema.table (based on availabilty)
- ':' . $dbConfig['port']
- .':' . $dbConfig['host']
- . '/' . $dbConfig['dbname'] . ':.products'
- );
- $idCacheActual = md5('/zf_test:.products');
- assert($cache->test($idCacheExpected));
- assert($cache->test($idCacheActual));
- }
- function _dropTable()
- {
- global $db;
- $db->query('DROP TABLE IF EXISTS products');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement