bootstrap.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  8. */
  9. if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
  10. define('PHP_CODESNIFFER_IN_TESTS', true);
  11. }
  12. if (defined('PHP_CODESNIFFER_CBF') === false) {
  13. define('PHP_CODESNIFFER_CBF', false);
  14. }
  15. if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
  16. define('PHP_CODESNIFFER_VERBOSITY', 0);
  17. }
  18. if (is_file(__DIR__.'/../autoload.php') === true) {
  19. include_once __DIR__.'/../autoload.php';
  20. } else {
  21. include_once 'PHP/CodeSniffer/autoload.php';
  22. }
  23. $tokens = new \PHP_CodeSniffer\Util\Tokens();
  24. // Compatibility for PHPUnit < 6 and PHPUnit 6+.
  25. if (class_exists('PHPUnit_Framework_TestSuite') === true && class_exists('PHPUnit\Framework\TestSuite') === false) {
  26. class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit'.'\Framework\TestSuite');
  27. }
  28. if (class_exists('PHPUnit_Framework_TestCase') === true && class_exists('PHPUnit\Framework\TestCase') === false) {
  29. class_alias('PHPUnit_Framework_TestCase', 'PHPUnit'.'\Framework\TestCase');
  30. }
  31. if (class_exists('PHPUnit_TextUI_TestRunner') === true && class_exists('PHPUnit\TextUI\TestRunner') === false) {
  32. class_alias('PHPUnit_TextUI_TestRunner', 'PHPUnit'.'\TextUI\TestRunner');
  33. }
  34. if (class_exists('PHPUnit_Framework_TestResult') === true && class_exists('PHPUnit\Framework\TestResult') === false) {
  35. class_alias('PHPUnit_Framework_TestResult', 'PHPUnit'.'\Framework\TestResult');
  36. }
  37. /**
  38. * A global util function to help print unit test fixing data.
  39. *
  40. * @return void
  41. */
  42. function printPHPCodeSnifferTestOutput()
  43. {
  44. $codes = count($GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']);
  45. echo PHP_EOL.PHP_EOL;
  46. echo "Tests generated $codes unique error codes";
  47. if ($codes > 0) {
  48. $fixes = count($GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']);
  49. $percent = round(($fixes / $codes * 100), 2);
  50. echo "; $fixes were fixable ($percent%)";
  51. }
  52. }//end printPHPCodeSnifferTestOutput()