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