TestHelper.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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-2012 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/Runner/Version.php';
  26. $phpunitVersion = PHPUnit_Runner_Version::id();
  27. if ($phpunitVersion == '@package_version@' || version_compare($phpunitVersion, '3.5.5', '>=')) {
  28. if (version_compare($phpunitVersion, '3.6.0', '>=')) {
  29. echo <<<EOT
  30. This version of PHPUnit is not supported in Zend Framework 1.x unit tests.
  31. To install PHPUnit 3.4:
  32. sudo pear config-set auto_discover 1
  33. sudo pear install --installroot /usr/local/phpunit34 pear.phpunit.de/PHPUnit-3.4.15
  34. This will install PHPUnit-3.4.15 to /usr/local/phpunit34.
  35. Now edit /usr/local/phpunit34/usr/bin/phpunit. Before the first
  36. require_once statement in that file, enter the following code:
  37. set_include_path(implode(PATH_SEPARATOR, array(
  38. __DIR__ . '/../share/php',
  39. '/usr/share/php',
  40. get_include_path()
  41. )));
  42. Note the actual directory (share/php in the code above) depends on your
  43. particular installation. The correct path can be found by typing:
  44. pear config-show|grep php_dir
  45. (on Centos it is share/php, on Ubuntu/Debian it is share/pear and on
  46. OS X it is lib/php/pear)
  47. Lastly, we need a symlink:
  48. sudo ln -s /some/path/phpunit34/usr/bin/phpunit /usr/bin/phpunit34
  49. Now you can run the unit tests with:
  50. phpunit34 --stderr -d memory_limit=-1 Zend/{Name}/AllTests.php
  51. (Based on information from Christer Edvartsen's article published at
  52. http://tech.vg.no/2011/11/29/running-multiple-versions-of-phpunit/)
  53. EOT;
  54. exit(1);
  55. }
  56. require_once 'PHPUnit/Autoload.php'; // >= PHPUnit 3.5.5
  57. } else {
  58. require_once 'PHPUnit/Framework.php'; // < PHPUnit 3.5.5
  59. }
  60. /*
  61. * Set error reporting to the level to which Zend Framework code must comply.
  62. */
  63. error_reporting(E_ALL | E_STRICT);
  64. /*
  65. * Determine the root, library, and tests directories of the framework
  66. * distribution.
  67. */
  68. $zfRoot = realpath(dirname(dirname(__FILE__)));
  69. $zfCoreLibrary = "$zfRoot/library";
  70. $zfCoreTests = "$zfRoot/tests";
  71. /*
  72. * Prepend the Zend Framework library/ and tests/ directories to the
  73. * include_path. This allows the tests to run out of the box and helps prevent
  74. * loading other copies of the framework code and tests that would supersede
  75. * this copy.
  76. */
  77. $path = array(
  78. $zfCoreLibrary,
  79. $zfCoreTests,
  80. get_include_path()
  81. );
  82. set_include_path(implode(PATH_SEPARATOR, $path));
  83. /*
  84. * Load the user-defined test configuration file, if it exists; otherwise, load
  85. * the default configuration.
  86. */
  87. if (is_readable($zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php')) {
  88. require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php';
  89. } else {
  90. require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php.dist';
  91. }
  92. /**
  93. * Start output buffering, if enabled
  94. */
  95. if (defined('TESTS_ZEND_OB_ENABLED') && constant('TESTS_ZEND_OB_ENABLED')) {
  96. ob_start();
  97. }
  98. /*
  99. * Unset global variables that are no longer needed.
  100. */
  101. unset($zfRoot, $zfCoreLibrary, $zfCoreTests, $path);
  102. // Suppress DateTime warnings
  103. date_default_timezone_set(@date_default_timezone_get());