TestHelper.php 3.1 KB

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