2
0

TestSetup.php 2.6 KB

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