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