bootstrap.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Bootstrap file for PHP_CodeSniffer unit tests.
  4. *
  5. * @author Greg Sherwood <gsherwood@squiz.net>
  6. * @copyright 2006-2017 Squiz Pty Ltd (ABN 77 084 670 600)
  7. * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  8. */
  9. use PHP_CodeSniffer\Autoload;
  10. use PHP_CodeSniffer\Util\Standards;
  11. use PHP_CodeSniffer\Util\Tokens;
  12. if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
  13. define('PHP_CODESNIFFER_IN_TESTS', true);
  14. }
  15. /*
  16. * Determine whether the test suite should be run in CBF mode.
  17. *
  18. * Use `<php><env name="PHP_CODESNIFFER_CBF" value="1"/></php>` in a `phpunit.xml` file
  19. * or set the ENV variable at an OS-level to enable CBF mode.
  20. *
  21. * To run the CBF specific tests, use the following command:
  22. * vendor/bin/phpunit --group CBF --exclude-group nothing
  23. *
  24. * If the ENV variable has not been set, or is set to "false", the tests will run in CS mode.
  25. */
  26. if (defined('PHP_CODESNIFFER_CBF') === false) {
  27. $cbfMode = getenv('PHP_CODESNIFFER_CBF');
  28. if ($cbfMode === '1') {
  29. define('PHP_CODESNIFFER_CBF', true);
  30. echo 'Note: Tests are running in "CBF" mode'.PHP_EOL.PHP_EOL;
  31. } else {
  32. define('PHP_CODESNIFFER_CBF', false);
  33. echo 'Note: Tests are running in "CS" mode'.PHP_EOL.PHP_EOL;
  34. }
  35. }
  36. if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
  37. define('PHP_CODESNIFFER_VERBOSITY', 0);
  38. }
  39. require_once __DIR__.'/../autoload.php';
  40. // Make sure all installed standards are autoloadable.
  41. $installedStandards = Standards::getInstalledStandardDetails();
  42. foreach ($installedStandards as $standardDetails) {
  43. Autoload::addSearchPath($standardDetails['path'], $standardDetails['namespace']);
  44. }
  45. $tokens = new Tokens();