TestSetup.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Db
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Db_TestSetup
  24. */
  25. require_once 'Zend/Db/TestSetup.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Db
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Db
  33. * @group Zend_Db_Table
  34. */
  35. abstract class Zend_Db_Table_TestSetup extends Zend_Db_TestSetup
  36. {
  37. /**
  38. * @var array of Zend_Db_Table_Abstract
  39. */
  40. protected $_table = array();
  41. protected $_runtimeIncludePath = null;
  42. public function setUp()
  43. {
  44. parent::setUp();
  45. $this->_table['accounts'] = $this->_getTable('My_ZendDbTable_TableAccounts');
  46. $this->_table['bugs'] = $this->_getTable('My_ZendDbTable_TableBugs');
  47. $this->_table['bugs_products'] = $this->_getTable('My_ZendDbTable_TableBugsProducts');
  48. $this->_table['products'] = $this->_getTable('My_ZendDbTable_TableProducts');
  49. }
  50. public function tearDown()
  51. {
  52. if ($this->_runtimeIncludePath) {
  53. $this->_restoreIncludePath();
  54. }
  55. parent::tearDown();
  56. }
  57. protected function _getTable($tableClass, $options = array())
  58. {
  59. if (is_array($options) && !isset($options['db'])) {
  60. $options['db'] = $this->_db;
  61. }
  62. if (!class_exists($tableClass)) {
  63. $this->_useMyIncludePath();
  64. Zend_Loader::loadClass($tableClass);
  65. $this->_restoreIncludePath();
  66. }
  67. $table = new $tableClass($options);
  68. return $table;
  69. }
  70. protected function _useMyIncludePath()
  71. {
  72. $this->_runtimeIncludePath = get_include_path();
  73. set_include_path(dirname(__FILE__) . '/_files/' . PATH_SEPARATOR . $this->_runtimeIncludePath);
  74. }
  75. protected function _restoreIncludePath()
  76. {
  77. set_include_path($this->_runtimeIncludePath);
  78. $this->_runtimeIncludePath = null;
  79. }
  80. }