Mercurial > hg > cmmr2012-drupal-site
comparison vendor/squizlabs/php_codesniffer/tests/Standards/AllSniffs.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | |
children | 12f9dff5fda9 |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
1 <?php | |
2 /** | |
3 * A test class for testing all sniffs for installed standards. | |
4 * | |
5 * @author Greg Sherwood <gsherwood@squiz.net> | |
6 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) | |
7 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | |
8 */ | |
9 | |
10 namespace PHP_CodeSniffer\Tests\Standards; | |
11 | |
12 use PHP_CodeSniffer\Util\Standards; | |
13 use PHP_CodeSniffer\Autoload; | |
14 use PHPUnit\TextUI\TestRunner; | |
15 use PHPUnit\Framework\TestSuite; | |
16 | |
17 class AllSniffs | |
18 { | |
19 | |
20 | |
21 /** | |
22 * Prepare the test runner. | |
23 * | |
24 * @return void | |
25 */ | |
26 public static function main() | |
27 { | |
28 TestRunner::run(self::suite()); | |
29 | |
30 }//end main() | |
31 | |
32 | |
33 /** | |
34 * Add all sniff unit tests into a test suite. | |
35 * | |
36 * Sniff unit tests are found by recursing through the 'Tests' directory | |
37 * of each installed coding standard. | |
38 * | |
39 * @return \PHPUnit\Framework\TestSuite | |
40 */ | |
41 public static function suite() | |
42 { | |
43 $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = []; | |
44 $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = []; | |
45 $GLOBALS['PHP_CODESNIFFER_SNIFF_CASE_FILES'] = []; | |
46 | |
47 $suite = new TestSuite('PHP CodeSniffer Standards'); | |
48 | |
49 $isInstalled = !is_file(__DIR__.'/../../autoload.php'); | |
50 | |
51 // Optionally allow for ignoring the tests for one or more standards. | |
52 $ignoreTestsForStandards = getenv('PHPCS_IGNORE_TESTS'); | |
53 if ($ignoreTestsForStandards === false) { | |
54 $ignoreTestsForStandards = []; | |
55 } else { | |
56 $ignoreTestsForStandards = explode(',', $ignoreTestsForStandards); | |
57 } | |
58 | |
59 $installedStandards = self::getInstalledStandardDetails(); | |
60 | |
61 foreach ($installedStandards as $standard => $details) { | |
62 Autoload::addSearchPath($details['path'], $details['namespace']); | |
63 | |
64 // If the test is running PEAR installed, the built-in standards | |
65 // are split into different directories; one for the sniffs and | |
66 // a different file system location for tests. | |
67 if ($isInstalled === true && is_dir(dirname($details['path']).DIRECTORY_SEPARATOR.'Generic') === true) { | |
68 $testPath = realpath(__DIR__.'/../../src/Standards/'.$standard); | |
69 } else { | |
70 $testPath = $details['path']; | |
71 } | |
72 | |
73 if (in_array($standard, $ignoreTestsForStandards) === true) { | |
74 continue; | |
75 } | |
76 | |
77 $testsDir = $testPath.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR; | |
78 if (is_dir($testsDir) === false) { | |
79 // No tests for this standard. | |
80 continue; | |
81 } | |
82 | |
83 $di = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($testsDir)); | |
84 | |
85 foreach ($di as $file) { | |
86 // Skip hidden files. | |
87 if (substr($file->getFilename(), 0, 1) === '.') { | |
88 continue; | |
89 } | |
90 | |
91 // Tests must have the extension 'php'. | |
92 $parts = explode('.', $file); | |
93 $ext = array_pop($parts); | |
94 if ($ext !== 'php') { | |
95 continue; | |
96 } | |
97 | |
98 $className = Autoload::loadFile($file->getPathname()); | |
99 $GLOBALS['PHP_CODESNIFFER_STANDARD_DIRS'][$className] = $details['path']; | |
100 $GLOBALS['PHP_CODESNIFFER_TEST_DIRS'][$className] = $testsDir; | |
101 $suite->addTestSuite($className); | |
102 } | |
103 }//end foreach | |
104 | |
105 return $suite; | |
106 | |
107 }//end suite() | |
108 | |
109 | |
110 /** | |
111 * Get the details of all coding standards installed. | |
112 * | |
113 * @return array | |
114 * @see Standards::getInstalledStandardDetails() | |
115 */ | |
116 protected static function getInstalledStandardDetails() | |
117 { | |
118 return Standards::getInstalledStandardDetails(true); | |
119 | |
120 }//end getInstalledStandardDetails() | |
121 | |
122 | |
123 }//end class |