TestHelper.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * @version $Id$
  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. */
  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 highest level.
  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 library/ and tests/ directories to the include_path.
  50. * 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. * Add library/ directory to the PHPUnit code coverage whitelist.
  71. * This has the effect that only production code source files appear
  72. * in the code coverage report and that all production code source files, even
  73. * those that are not covered by a test yet, are processed.
  74. */
  75. if (defined('TESTS_ZEND_SERVICE_WINDOWSAZURE_GENERATE_REPORT') && TESTS_ZEND_SERVICE_WINDOWSAZURE_GENERATE_REPORT === true &&
  76. version_compare(PHPUnit_Runner_Version::id(), '3.1.6', '>=')) {
  77. PHPUnit_Util_Filter::addDirectoryToWhitelist($zfCoreLibrary);
  78. }
  79. /*
  80. * Unset global variables that are no longer needed.
  81. */
  82. unset($zfRoot, $zfCoreLibrary, $zfCoreTests, $path);