TestHelper.php 3.1 KB

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