-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
phpunit-bootstrap.php
105 lines (84 loc) · 3.21 KB
/
phpunit-bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
*
* Bootstrap file for running the tests.
*
* - Load the PHPCS PHPUnit bootstrap file providing cross-version PHPUnit support.
* {@link https://github.com/squizlabs/PHP_CodeSniffer/pull/1384}
*
* @package PHPCSDevTools
* @copyright 2019 PHPCSDevTools Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSDevTools
*/
if (\defined('PHP_CODESNIFFER_IN_TESTS') === false) {
\define('PHP_CODESNIFFER_IN_TESTS', true);
}
if (\defined('PHP_CODESNIFFER_CBF') === false) {
\define('PHP_CODESNIFFER_CBF', false);
}
if (\defined('PHP_CODESNIFFER_VERBOSITY') === false) {
\define('PHP_CODESNIFFER_VERBOSITY', 0);
}
$ds = \DIRECTORY_SEPARATOR;
/*
* Load the necessary PHPCS files.
*/
// Get the PHPCS dir from an environment variable.
$phpcsDir = \getenv('PHPCS_DIR');
// Get the PHPCSUtils dir from an environment variable.
$phpcsUtilsDir = \getenv('PHPCSUTILS_DIR');
// This may be a Composer install.
if (\is_dir(__DIR__ . $ds . 'vendor')) {
$vendorDir = __DIR__ . $ds . 'vendor';
if ($phpcsDir === false && \is_dir($vendorDir . $ds . 'squizlabs' . $ds . 'php_codesniffer')) {
$phpcsDir = $vendorDir . $ds . 'squizlabs' . $ds . 'php_codesniffer';
}
if ($phpcsUtilsDir === false && \is_dir($vendorDir . $ds . 'phpcsstandards' . $ds . 'phpcsutils')) {
$phpcsUtilsDir = $vendorDir . $ds . 'phpcsstandards' . $ds . 'phpcsutils';
}
}
if ($phpcsDir !== false) {
$phpcsDir = \realpath($phpcsDir);
}
if ($phpcsUtilsDir !== false) {
$phpcsUtilsDir = \realpath($phpcsUtilsDir);
}
// Try and load the PHPCS autoloader.
if ($phpcsDir !== false && \file_exists($phpcsDir . $ds . 'autoload.php')) {
// PHPCS 3.x.
require_once $phpcsDir . $ds . 'autoload.php';
// Pre-load the token back-fills to prevent undefined constant notices.
require_once $phpcsDir . '/src/Util/Tokens.php';
} else {
echo 'Uh oh... can\'t find PHPCS.
If you use Composer, please run `composer install`.
Otherwise, make sure you set a `PHPCS_DIR` environment variable in your phpunit.xml file
pointing to the PHPCS directory.
';
die(1);
}
$installedStandards = \PHP_CodeSniffer\Util\Standards::getInstalledStandardDetails();
foreach ($installedStandards as $details) {
\PHP_CodeSniffer\Autoload::addSearchPath($details['path'], $details['namespace']);
}
// Try and load the PHPCSUtils autoloader.
if ($phpcsUtilsDir !== false && \file_exists($phpcsUtilsDir . $ds . 'phpcsutils-autoload.php')) {
require_once $phpcsUtilsDir . $ds . 'phpcsutils-autoload.php';
} else {
echo 'Uh oh... can\'t find PHPCSUtils.
If you use Composer, please run `composer install`.
Otherwise, make sure you set a `PHPCSUTILS_DIR` environment variable in your phpunit.xml file
pointing to the PHPCSUtils directory.
';
die(1);
}
// Load autoloader for the non-sniff devtools and tests.
require_once __DIR__ . '/devtools-autoload.php';
// Load test related autoloader.
require_once __DIR__ . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php';
// Load IO testcase.
require_once __DIR__ . '/Tests/IOTestCase.php';
// Clean up.
unset($ds, $phpcsDir, $phpcsUtilsDir, $vendorDir);