TestHelper.php 3.0 KB

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