12
12
use PHP_CodeSniffer \Util \Tokens ;
13
13
use PHP_CodeSniffer \Util \Standards ;
14
14
use PHP_CodeSniffer \Autoload ;
15
+ use PHP_CodeSniffer \Tests \Standards \AbstractSniffUnitTest ;
15
16
16
17
if (defined ('PHP_CODESNIFFER_IN_TESTS ' ) === false ) {
17
18
define ('PHP_CODESNIFFER_IN_TESTS ' , true );
25
26
define ('PHP_CODESNIFFER_VERBOSITY ' , 0 );
26
27
}
27
28
28
- require_once __DIR__ .'/../../autoload.php ' ;
29
+ if (is_file (__DIR__ .'/../../autoload.php ' ) === true ) {
30
+ include_once __DIR__ .'/../../autoload.php ' ;
31
+ } else {
32
+ include_once 'PHP/CodeSniffer/autoload.php ' ;
33
+ }
29
34
30
35
$ tokens = new Tokens ();
31
36
@@ -60,38 +65,34 @@ public static function suite()
60
65
61
66
$ suite = new \PHPUnit_Framework_TestSuite ('PHP CodeSniffer Standards ' );
62
67
63
- /*
64
- $isInstalled = !is_file(dirname(__FILE__).'/../../CodeSniffer.php');
65
- */
68
+ $ isInstalled = !is_file (__DIR__ .'/../../autoload.php ' );
66
69
67
70
$ installedPaths = Standards::getInstalledStandardPaths ();
71
+
68
72
foreach ($ installedPaths as $ path ) {
69
73
$ standards = Standards::getInstalledStandards (true , $ path );
70
74
71
- /*
72
- // If the test is running PEAR installed, the built-in standards
73
- // are split into different directories; one for the sniffs and
74
- // a different file system location for tests.
75
- if ($isInstalled === true
76
- && is_dir($path.DIRECTORY_SEPARATOR.'Generic') === true
77
- ) {
78
- $path = dirname(__FILE__);
79
- }
80
- */
75
+ // If the test is running PEAR installed, the built-in standards
76
+ // are split into different directories; one for the sniffs and
77
+ // a different file system location for tests.
78
+ if ($ isInstalled === true && is_dir ($ path .DIRECTORY_SEPARATOR .'Generic ' ) === true ) {
79
+ $ testPath = realpath (__DIR__ .'/../../src/Standards ' );
80
+ } else {
81
+ $ testPath = $ path ;
82
+ }
81
83
82
84
foreach ($ standards as $ standard ) {
83
85
$ standardDir = $ path .DIRECTORY_SEPARATOR .$ standard ;
84
- $ testsDir = $ standardDir .DIRECTORY_SEPARATOR .'Tests ' .DIRECTORY_SEPARATOR ;
86
+ $ testsDir = $ testPath . DIRECTORY_SEPARATOR . $ standard .DIRECTORY_SEPARATOR .'Tests ' .DIRECTORY_SEPARATOR ;
85
87
86
88
if (is_dir ($ testsDir ) === false ) {
87
89
// Check if the installed path is actually a standard itself.
88
90
$ standardDir = $ path ;
89
- $ testsDir = $ standardDir .DIRECTORY_SEPARATOR .'Tests ' .DIRECTORY_SEPARATOR ;
91
+ $ testsDir = $ testPath .DIRECTORY_SEPARATOR .'Tests ' .DIRECTORY_SEPARATOR ;
90
92
if (is_dir ($ testsDir ) === false ) {
91
93
// No tests for this standard.
92
94
continue ;
93
95
}
94
- } else {
95
96
}
96
97
97
98
$ di = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ testsDir ));
@@ -111,6 +112,7 @@ public static function suite()
111
112
112
113
$ className = Autoload::loadFile ($ file ->getPathname ());
113
114
$ GLOBALS ['PHP_CODESNIFFER_STANDARD_DIRS ' ][$ className ] = $ standardDir ;
115
+ $ GLOBALS ['PHP_CODESNIFFER_TEST_DIRS ' ][$ className ] = $ testsDir ;
114
116
$ suite ->addTestSuite ($ className );
115
117
}
116
118
}//end foreach
0 commit comments