phpunit-bootstrap.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * PHPCompatibility, an external standard for PHP_CodeSniffer.
  4. *
  5. * Bootstrap file for tests.
  6. *
  7. * @package PHPCompatibility
  8. * @copyright 2012-2019 PHPCompatibility Contributors
  9. * @license https://opensource.org/licenses/LGPL-3.0 LGPL3
  10. * @link https://github.com/PHPCompatibility/PHPCompatibility
  11. *
  12. * @since 5.5
  13. */
  14. if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
  15. define('PHP_CODESNIFFER_IN_TESTS', true);
  16. }
  17. // The below two defines are needed for PHPCS 3.x.
  18. if (defined('PHP_CODESNIFFER_CBF') === false) {
  19. define('PHP_CODESNIFFER_CBF', false);
  20. }
  21. if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
  22. define('PHP_CODESNIFFER_VERBOSITY', 0);
  23. }
  24. $ds = DIRECTORY_SEPARATOR;
  25. // Get the PHPCS dir from an environment variable.
  26. $phpcsDir = getenv('PHPCS_DIR');
  27. // This may be a Composer install.
  28. if ($phpcsDir === false && is_dir(__DIR__ . $ds . 'vendor' . $ds . 'squizlabs' . $ds . 'php_codesniffer')) {
  29. $vendorDir = __DIR__ . $ds . 'vendor';
  30. $phpcsDir = $vendorDir . $ds . 'squizlabs' . $ds . 'php_codesniffer';
  31. } elseif ($phpcsDir !== false) {
  32. $phpcsDir = realpath($phpcsDir);
  33. }
  34. // Try and load the PHPCS autoloader.
  35. if ($phpcsDir !== false && file_exists($phpcsDir . $ds . 'autoload.php')) {
  36. // PHPCS 3.x.
  37. require_once $phpcsDir . $ds . 'autoload.php';
  38. /*
  39. * Alias the PHPCS 3.x classes to their PHPCS 2.x equivalent if necessary.
  40. * Also provide a custom autoloader for our abstract base classes as the PHPCS native autoloader
  41. * has trouble with them in combination with the PHPCompatibility custom unit test suite.
  42. */
  43. require_once __DIR__ . $ds . 'PHPCSAliases.php';
  44. } elseif ($phpcsDir !== false && file_exists($phpcsDir . $ds . 'CodeSniffer.php')) {
  45. // PHPCS 2.x.
  46. require_once $phpcsDir . $ds . 'CodeSniffer.php';
  47. if (isset($vendorDir) && file_exists($vendorDir . $ds . 'autoload.php')) {
  48. require_once $vendorDir . $ds . 'autoload.php';
  49. }
  50. } else {
  51. echo 'Uh oh... can\'t find PHPCS.
  52. If you use Composer, please run `composer install --prefer-source`.
  53. Otherwise, make sure you set a `PHPCS_DIR` environment variable in your phpunit.xml file
  54. pointing to the PHPCS directory.
  55. Please read the contributors guidelines for more information:
  56. https://is.gd/PHPCompatibilityContrib
  57. ';
  58. die(1);
  59. }
  60. // PHPUnit cross version compatibility.
  61. if (class_exists('PHPUnit\Runner\Version')
  62. && version_compare(PHPUnit\Runner\Version::id(), '6.0', '>=')
  63. && class_exists('PHPUnit_Framework_TestCase') === false
  64. ) {
  65. class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
  66. }
  67. require_once __DIR__ . $ds . 'PHPCompatibility' . $ds . 'Tests' . $ds . 'BaseSniffTest.php';
  68. require_once __DIR__ . $ds . 'PHPCompatibility' . $ds . 'Util' . $ds . 'Tests' . $ds . 'CoreMethodTestFrame.php';
  69. unset($ds, $phpcsDir, $vendorDir);