-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpunit.php
104 lines (87 loc) · 3.1 KB
/
phpunit.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
<?php
/**
* This file is part of the West\\CodingStandard package
*
* (c) Chris Evans <cvns.github@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace West\CodingStandard;
use PHP_CodeSniffer\Tests\TestSuite as CodeSnifferTestSuite;
use PHP_CodeSniffer\Util\Standards;
use PHP_CodeSniffer\Autoload;
use PHPUnit\Framework\TestSuite;
/**
* Test suite for the West coding standard.
*/
class AllTests
{
/**
* Add all PHP_CodeSniffer test suites into a single test suite.
*
* @return \PHPUnit\Framework\TestSuite
*/
public static function suite()
{
$GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'] = [];
$GLOBALS['PHP_CODESNIFFER_TEST_DIRS'] = [];
// Use a special PHP_CodeSniffer test suite so that we can
// unset our autoload function after the run.
$suite = new CodeSnifferTestSuite('West');
$suite->addTest(self::sniff_suite());
return $suite;
}
/**
* Add all sniff unit tests into a test suite.
*
* Sniff unit tests are found by recursing through the 'Tests' directory
* of each installed coding standard.
*
* @return \PHPUnit\Framework\TestSuite
*/
public static function sniff_suite()
{
$GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = [];
$GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = [];
$suite = new TestSuite('West PHP CodeSniffer Standards');
$installedStandards = self::getInstalledStandardDetails();
foreach ($installedStandards as $standard => $details) {
//Autoload::addSearchPath($details['path'], $details['namespace']);
$testPath = $details['path'];
$testsDir = $testPath . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR;
if (is_dir($testsDir) === false) {
// No tests for this standard.
continue;
}
$di = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($testsDir));
foreach ($di as $file) {
// Skip hidden files.
if (substr($file->getFilename(), 0, 1) === '.') {
continue;
}
// Tests must have the extension 'php'.
$parts = explode('.', $file);
$ext = array_pop($parts);
if ($ext !== 'php') {
continue;
}
$className = Autoload::loadFile($file->getPathname());
$GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $details['path'];
$GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$className] = $testsDir;
$suite->addTestSuite($className);
}
}
return $suite;
}
/**
* Get the details of all coding standards installed.
*
* @return array
* @see Standards::getInstalledStandardDetails()
*/
protected static function getInstalledStandardDetails()
{
return Standards::getInstalledStandardDetails(true, realpath(__DIR__));
}
}