2
0

TestSetup.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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-2009 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-2009 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. }
  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. }