-
Notifications
You must be signed in to change notification settings - Fork 84
/
phpunit-bootstrap.php
78 lines (65 loc) · 2.39 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
<?php
/**
* 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}
* - Allows for a `PHPCS_DIR` environment variable to be set to point to a different
* PHPCS install than the one in the `vendor` directory to allow for testing with
* a git clone of PHPCS in a local develop environment.
* - Prevent attempting to run unit tests of other external PHPCS standards installed.
*/
if (\defined('PHP_CODESNIFFER_IN_TESTS') === false) {
\define('PHP_CODESNIFFER_IN_TESTS', true);
}
$ds = \DIRECTORY_SEPARATOR;
/*
* Load the necessary PHPCS files.
*/
// Get the PHPCS dir from an environment variable.
$phpcsDir = \getenv('PHPCS_DIR');
$composerPHPCSPath = __DIR__ . $ds . 'vendor' . $ds . 'squizlabs' . $ds . 'php_codesniffer';
if ($phpcsDir === false && \is_dir($composerPHPCSPath)) {
// PHPCS installed via Composer.
$phpcsDir = $composerPHPCSPath;
} elseif ($phpcsDir !== false) {
/*
* PHPCS in a custom directory.
* For this to work, the `PHPCS_DIR` variable needs to be set in a custom `phpunit.xml` file.
*/
$phpcsDir = \realpath($phpcsDir);
}
// Try and load the PHPCS autoloader.
if ($phpcsDir !== false
&& \file_exists($phpcsDir . $ds . 'autoload.php')
&& \file_exists($phpcsDir . $ds . 'tests' . $ds . 'bootstrap.php')
) {
require_once $phpcsDir . $ds . 'autoload.php';
require_once $phpcsDir . $ds . 'tests' . $ds . 'bootstrap.php'; // PHPUnit 6.x+ support.
} 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);
}
/*
* Set the PHPCS_IGNORE_TEST environment variable to ignore tests from other standards.
*/
$securityStandards = [
'Security' => true,
];
$allStandards = PHP_CodeSniffer\Util\Standards::getInstalledStandards();
$allStandards[] = 'Generic';
$standardsToIgnore = [];
foreach ($allStandards as $standard) {
if (isset($securityStandards[$standard]) === true) {
continue;
}
$standardsToIgnore[] = $standard;
}
$standardsToIgnoreString = \implode(',', $standardsToIgnore);
\putenv("PHPCS_IGNORE_TESTS={$standardsToIgnoreString}");
// Clean up.
unset($ds, $phpcsDir, $composerPHPCSPath, $allStandards, $standardsToIgnore, $standard, $standardsToIgnoreString);