TestHelper.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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
  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. * Include PHPUnit dependencies
  24. */
  25. require_once 'PHPUnit/Framework.php';
  26. require_once 'PHPUnit/Framework/IncompleteTestError.php';
  27. require_once 'PHPUnit/Framework/TestCase.php';
  28. require_once 'PHPUnit/Framework/TestSuite.php';
  29. require_once 'PHPUnit/Runner/Version.php';
  30. require_once 'PHPUnit/TextUI/TestRunner.php';
  31. require_once 'PHPUnit/Util/Filter.php';
  32. /*
  33. * Set error reporting to the level to which Zend Framework code must comply.
  34. */
  35. error_reporting( E_ALL | E_STRICT );
  36. /*
  37. * Determine the root, library, and tests directories of the framework
  38. * distribution.
  39. */
  40. $zfRoot = realpath(dirname(dirname(__FILE__)));
  41. $zfCoreLibrary = "$zfRoot/library";
  42. $zfCoreTests = "$zfRoot/tests";
  43. /*
  44. * Prepend the Zend Framework library/ and tests/ directories to the
  45. * include_path. This allows the tests to run out of the box and helps prevent
  46. * loading other copies of the framework code and tests that would supersede
  47. * this copy.
  48. */
  49. $path = array(
  50. $zfCoreLibrary,
  51. $zfCoreTests,
  52. get_include_path()
  53. );
  54. set_include_path(implode(PATH_SEPARATOR, $path));
  55. /*
  56. * Load the user-defined test configuration file, if it exists; otherwise, load
  57. * the default configuration.
  58. */
  59. if (is_readable($zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php')) {
  60. require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php';
  61. } else {
  62. require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php.dist';
  63. }
  64. if (defined('TESTS_GENERATE_REPORT') && TESTS_GENERATE_REPORT === true &&
  65. version_compare(PHPUnit_Runner_Version::id(), '3.1.6', '>=')) {
  66. /*
  67. * Add Zend Framework library/ directory to the PHPUnit code coverage
  68. * whitelist. This has the effect that only production code source files
  69. * appear in the code coverage report and that all production code source
  70. * files, even those that are not covered by a test yet, are processed.
  71. */
  72. PHPUnit_Util_Filter::addDirectoryToWhitelist($zfCoreLibrary);
  73. /*
  74. * Omit from code coverage reports the contents of the tests directory
  75. */
  76. foreach (array('.php', '.phtml', '.csv', '.inc') as $suffix) {
  77. PHPUnit_Util_Filter::addDirectoryToFilter($zfCoreTests, $suffix);
  78. }
  79. PHPUnit_Util_Filter::addDirectoryToFilter(PEAR_INSTALL_DIR);
  80. PHPUnit_Util_Filter::addDirectoryToFilter(PHP_LIBDIR);
  81. }
  82. /**
  83. * Start output buffering, if enabled
  84. */
  85. if (defined('TESTS_ZEND_OB_ENABLED') && constant('TESTS_ZEND_OB_ENABLED')) {
  86. ob_start();
  87. }
  88. /*
  89. * Unset global variables that are no longer needed.
  90. */
  91. unset($zfRoot, $zfCoreLibrary, $zfCoreTests, $path);