forked from totara/code-sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
50 lines (40 loc) · 1.68 KB
/
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
<?php
/**
* @author Fabian Derschatta <[email protected]>
* @copyright Copyright (C) 2018 onwards Totara Learning Solutions LTD.
* @license https://git.totaralearning.com/projects/GENERAL/repos/code-sniffer/browse/LICENCE.txt BSD Licence
*/
require 'vendor/autoload.php';
$GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = [];
$GLOBALS['PHP_CODESNIFFER_TEST_DIRS'] = [];
$testNamespaceBase = 'Totara\CodeSniffer\Standards\Totara\Sniffs';
$srcPath = __DIR__.'/src/Standards/Totara/';
$testPath = __DIR__.'/tests/Standards/Totara/Sniffs/';
$testClasses = [];
// Dynamically determine the class names for our test files.
// This is needed for the CodeSniffer unit tests.
$allTestFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($testPath));
$testFiles = new RegexIterator($allTestFiles, '/Test\.php$/');
foreach ($testFiles as $testFile) {
$namespaceName = '';
$className = '';
$tokenStream = new PHP_Token_Stream($testFile->getPathname());
foreach ($tokenStream as $token) {
if ($token instanceof PHP_Token_NAMESPACE) {
$namespaceName = $token->getName();
}
if ($token instanceof PHP_Token_CLASS) {
$className = $token->getName();
}
}
if (strpos($namespaceName, $testNamespaceBase) !== false) {
$testClasses[] = "{$namespaceName}\\{$className}";
}
}
foreach ($testClasses as $class) {
$GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$class] = $srcPath;
$GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$class] = $testPath;
}
$GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = [];
$GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = [];
require __DIR__.'/vendor/squizlabs/php_codesniffer/tests/bootstrap.php';