Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

ZF-10778

By: a guest on Dec 4th, 2010  |  syntax: PHP  |  size: 1.90 KB  |  views: 191  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. error_reporting(E_ALL | E_STRICT);
  3. ini_set('display_errors', 1);
  4.  
  5. $paths = array(
  6.     '/var/www/zf-trunk/library',
  7.     '/var/www/test/library'
  8. );
  9. set_include_path(implode(PATH_SEPARATOR, $paths));
  10. require_once 'Zend/Loader/Autoloader.php';
  11. Zend_Loader_Autoloader::getInstance();
  12.  
  13. $db    = null;
  14. $cache = null;
  15.  
  16. _setupDb();
  17. _dropTable();
  18. _createTable();
  19. _setupCache();
  20. _compareCache();
  21. _dropTable();
  22.  
  23. function _setupDb()
  24. {
  25.     global $db;
  26.     $config = array(
  27.         'dbname'   => 'zf_test',
  28.         'username' => 'root',
  29.         'password' => '',
  30.         'host'     => '127.0.0.1',
  31.         'port'     => '3306'
  32.     );
  33.     $db = Zend_Db::factory('Pdo_Mysql', $config);
  34.     Zend_Db_Table::setDefaultAdapter($db);
  35. }
  36.  
  37. function _setupCache()
  38. {
  39.     global $cache;
  40.     $cache = Zend_Cache::factory('Core', 'File', array('automatic_serialization' => true));
  41.     $cache->clean();
  42.     Zend_Db_Table::setDefaultMetadataCache($cache);
  43. }
  44.  
  45. function _createTable()
  46. {
  47.     global $db;
  48.     $db->query('DROP TABLE IF EXISTS products');
  49.     $sql = <<<SQL
  50.     CREATE TABLE products (
  51.         product_id        INTEGER NOT NULL PRIMARY KEY,
  52.         product_name      VARCHAR(100)
  53.     );
  54. SQL;
  55.     $db->query($sql);
  56.  
  57. }
  58.  
  59. function _compareIdCache()
  60. {
  61.     global $db, $cache;
  62.     $table = new Zend_Db_Table('products');
  63.     $table->info(Zend_Db_Table::METADATA);
  64.     $dbConfig = $db->getConfig();
  65.     $idCacheExpected  = md5( // port:host/dbname:schema.table (based on availabilty)
  66.                          ':' . $dbConfig['port']
  67.                         .':' . $dbConfig['host']
  68.                         . '/' . $dbConfig['dbname'] . ':.products'
  69.     );
  70.     $idCacheActual = md5('/zf_test:.products');
  71.  
  72.     assert($cache->test($idCacheExpected));
  73.     assert($cache->test($idCacheActual));
  74. }
  75.  
  76. function _dropTable()
  77. {
  78.     global $db;
  79.     $db->query('DROP TABLE IF EXISTS products');
  80. }
clone this paste RAW Paste Data