| 1 |
<?php |
| 2 |
/** |
| 3 |
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers. |
| 4 |
* |
| 5 |
* Autoloader for the PHPCSUtils files. |
| 6 |
* Also provides PHPCS cross-version class aliases. |
| 7 |
* |
| 8 |
* - If an external standard only supports PHPCS >= 3.1.0 and uses the PHPCS |
| 9 |
* native unit test framework, this file does not need to be included. |
| 10 |
* |
| 11 |
* - If an external standard uses its own unit test setup, this file should |
| 12 |
* be included from the unit test bootstrap file. |
| 13 |
* |
| 14 |
* - If an external standard uses the PHPCSUtils {@see PHPCSUtils\TestUtils\UtilityMethodTestCase} |
| 15 |
* class to test their own utility methods, this file should be included from |
| 16 |
* the unit test bootstrap file. |
| 17 |
* |
| 18 |
* @package PHPCSUtils |
| 19 |
* @copyright 2019-2020 PHPCSUtils Contributors |
| 20 |
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3 |
| 21 |
* @link https://github.com/PHPCSStandards/PHPCSUtils |
| 22 |
* |
| 23 |
* @since 1.0.0 |
| 24 |
*/ |
| 25 |
|
| 26 |
if (defined('PHPCSUTILS_AUTOLOAD') === false) { |
| 27 |
/* |
| 28 |
* Register an autoloader. |
| 29 |
* |
| 30 |
* External PHPCS standards which have their own unit test suite |
| 31 |
* should include this file in their test runner bootstrap. |
| 32 |
*/ |
| 33 |
spl_autoload_register(function ($fqClassName) { |
| 34 |
// Only try & load our own classes. |
| 35 |
if (stripos($fqClassName, 'PHPCSUtils') !== 0) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
$file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($fqClassName, '\\', DIRECTORY_SEPARATOR) . '.php'; |
| 40 |
|
| 41 |
if (file_exists($file)) { |
| 42 |
include_once $file; |
| 43 |
} |
| 44 |
}); |
| 45 |
|
| 46 |
define('PHPCSUTILS_AUTOLOAD', true); |
| 47 |
} |
| 48 |
|
| 49 |
if (defined('PHPCSUTILS_PHPUNIT_ALIASES_SET') === false) { |
| 50 |
/* |
| 51 |
* Alias the PHPUnit 4/5 TestCase class to its PHPUnit 6+ name. |
| 52 |
* |
| 53 |
* This allows both the PHPCSUtils native unit tests as well as the |
| 54 |
* `UtilityMethodTestCase` class to work cross-version with PHPUnit |
| 55 |
* below 6.x and above. |
| 56 |
* |
| 57 |
* {@internal The `class_exists` wrappers are needed to play nice with |
| 58 |
* PHPUnit bootstrap files of external standards which may be creating |
| 59 |
* cross-version compatibility in a similar manner.}} |
| 60 |
*/ |
| 61 |
if (class_exists('PHPUnit_Framework_TestCase') === true |
| 62 |
&& class_exists('PHPUnit\Framework\TestCase') === false |
| 63 |
) { |
| 64 |
class_alias('PHPUnit_Framework_TestCase', 'PHPUnit\Framework\TestCase'); |
| 65 |
} |
| 66 |
|
| 67 |
define('PHPCSUTILS_PHPUNIT_ALIASES_SET', true); |
| 68 |
} |
| 69 |
|