|
13 | 13 | * @license gpl-2.0-or-later
|
14 | 14 | */
|
15 | 15 |
|
16 |
| -if ( ! \defined( 'PHP_CODESNIFFER_IN_TESTS' ) ) { |
| 16 | +if ( ! defined( 'PHP_CODESNIFFER_IN_TESTS' ) ) { |
17 | 17 | define( 'PHP_CODESNIFFER_IN_TESTS', true );
|
18 | 18 | }
|
19 | 19 |
|
20 | 20 | $ds = DIRECTORY_SEPARATOR;
|
21 | 21 |
|
22 | 22 | // Get the PHPCS dir from an environment variable.
|
23 |
| -$phpcsDir = getenv( 'PHPCS_DIR' ); |
| 23 | +$phpcsDir = getenv( 'PHPCS_DIR' ); |
| 24 | +$composerPHPCSPath = dirname( __DIR__ ) . $ds . 'vendor' . $ds . 'squizlabs' . $ds . 'php_codesniffer'; |
24 | 25 |
|
25 | 26 | // This may be a Composer install.
|
26 |
| -if ( false === $phpcsDir && is_dir( dirname( __DIR__ ) . $ds . 'vendor' . $ds . 'squizlabs' . $ds . 'php_codesniffer' ) ) { |
27 |
| - $phpcsDir = dirname( __DIR__ ) . $ds . 'vendor' . $ds . 'squizlabs' . $ds . 'php_codesniffer'; |
| 27 | +if ( false === $phpcsDir && is_dir( $composerPHPCSPath ) ) { |
| 28 | + $phpcsDir = $composerPHPCSPath; |
28 | 29 | } elseif ( false !== $phpcsDir ) {
|
| 30 | + // PHPCS in a custom directory. |
29 | 31 | $phpcsDir = realpath( $phpcsDir );
|
30 | 32 | }
|
31 | 33 |
|
32 | 34 | // Try and load the PHPCS autoloader.
|
33 |
| -if ( false !== $phpcsDir && file_exists( $phpcsDir . $ds . 'autoload.php' ) ) { |
| 35 | +if ( false !== $phpcsDir |
| 36 | + && file_exists( $phpcsDir . $ds . 'autoload.php' ) |
| 37 | + && file_exists( $phpcsDir . $ds . 'tests' . $ds . 'bootstrap.php' ) |
| 38 | +) { |
34 | 39 | require_once $phpcsDir . $ds . 'autoload.php';
|
35 | 40 |
|
36 | 41 | /*
|
|
39 | 44 | */
|
40 | 45 | require_once $phpcsDir . $ds . 'tests' . $ds . 'bootstrap.php';
|
41 | 46 | } else {
|
42 |
| - echo 'Uh oh... can\'t find PHPCS. Are you sure you are using PHPCS 3.x ? |
| 47 | + echo 'Uh oh... can\'t find PHPCS. |
43 | 48 |
|
44 | 49 | If you use Composer, please run `composer install`.
|
45 | 50 | Otherwise, make sure you set a `PHPCS_DIR` environment variable in your phpunit.xml file
|
46 | 51 | pointing to the PHPCS directory.
|
47 | 52 |
|
48 | 53 | Please read the contributors guidelines for more information:
|
49 |
| -https://is.gd/contributing2WPCS |
| 54 | +https://github.com/Automattic/VIP-Coding-Standards/blob/develop/.github/CONTRIBUTING.md |
50 | 55 | ';
|
51 | 56 |
|
52 | 57 | die( 1 );
|
53 | 58 | }
|
54 | 59 |
|
55 |
| -unset( $ds, $phpcsDir ); |
| 60 | +/* |
| 61 | + * Set the PHPCS_IGNORE_TEST environment variable to ignore tests from other standards. |
| 62 | + */ |
| 63 | +$vipcsStandards = [ |
| 64 | + 'WordPressVIPMinimum' => true, |
| 65 | +]; |
| 66 | + |
| 67 | +$allStandards = PHP_CodeSniffer\Util\Standards::getInstalledStandards(); |
| 68 | +$allStandards[] = 'Generic'; |
| 69 | + |
| 70 | +$standardsToIgnore = []; |
| 71 | +foreach ( $allStandards as $standard ) { |
| 72 | + if ( isset( $vipcsStandards[ $standard ] ) === true ) { |
| 73 | + continue; |
| 74 | + } |
| 75 | + |
| 76 | + $standardsToIgnore[] = $standard; |
| 77 | +} |
| 78 | + |
| 79 | +$standardsToIgnoreString = implode( ',', $standardsToIgnore ); |
| 80 | + |
| 81 | +// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_putenv -- This is test code, not production. |
| 82 | +putenv( "PHPCS_IGNORE_TESTS={$standardsToIgnoreString}" ); |
| 83 | + |
| 84 | +// Clean up. |
| 85 | +unset( $ds, $phpcsDir, $composerPHPCSPath, $allStandards, $standardsToIgnore, $standard, $standardsToIgnoreString ); |
0 commit comments