Skip to content

Commit 1e018ab

Browse files
committed
Tests: run against the *new* PHPCS 4 branch
The PHP_CodeSniffer 4.0 branch has been completely rebuild. See PHPCSStandards/PHP_CodeSniffer#120 for more detailed information about the "why". In practice, this means that to test against the upcoming PHPCS 4.0 release, we need to test against the `4.x` branch now, not the old `4.0` branch. A 4.0 beta/RC release is expected in the next few days. Once that is out, a test period starts and depending on whether problems are found or not, the 4.0.0 release will be tagged about a month later (or later if significant problems were found). When 4.0.0 gets tagged, the PHPCS `master` branch will be renamed to `3.x` and the `4.x` branch will be the new "main" branch for PHPCS, so more changes will be needed, but that's for later. Includes updating to the `DemoSniff` test fixture setup as PHPCS 4.0 will start enforcing for sniffs to implement the `Sniff` interface.
1 parent 648b84f commit 1e018ab

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

tests/PHPCSVersions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class PHPCSVersions
2727
*
2828
* @var string
2929
*/
30-
const NEXT_MAJOR = '4.0.x-dev as 3.9.99';
30+
const NEXT_MAJOR = '4.x-dev as 3.9.99';
3131

3232
/**
3333
* List of all PHPCS version which are supported by this plugin.

tests/fixtures/dummy-subdir/DummySubDir/Sniffs/Demo/DemoSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace DummySubDir\Sniffs\Demo;
1212

13+
use PHP_CodeSniffer_Sniff as PHPCS_Sniff;
14+
1315
/**
1416
* Dummy sniff which can be used to verify that PHPCS runs with an external standard.
1517
*
@@ -18,7 +20,7 @@
1820
* This is to allow the sniff to be compatible with both PHPCS 2.x as well as 3.x
1921
* without too much other work-arounds being needed.
2022
*/
21-
class DemoSniff
23+
class DemoSniff implements PHPCS_Sniff
2224
{
2325
/**
2426
* Registers the tokens that this sniff wants to listen for.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* PHPCS 2.x Had the `PHP_CodeSniffer_Sniff` interface...
4+
* PHPCS 3.x ... renamed that to `PHP_CodeSniffer\Sniffs\Sniff` and ...
5+
* PHPCS 4.x ... demands that sniffs implement the interface.
6+
*
7+
* Additionally, the Ruleset `<autoload>` directive is only supported as of PHPCS 3.0.
8+
*
9+
* So... for a test fixture "sniff" to be cross-version compatible:
10+
* - it must implement the `Sniff` interface for PHPCS 4 compatibility.
11+
* - which will need to be class aliased for PHPCS 2 vs 3 compatibility.
12+
*
13+
* That's what's being done here.
14+
*
15+
* And we need to alias to the PHPCS 2.x name as only 3.x can include this autoload file using `<autoload>`.
16+
*/
17+
18+
if ( ! defined( 'PHPCS_ALIASES_SET' ) ) {
19+
if ( ! class_exists( '\PHP_CodeSniffer_Sniff' ) ) {
20+
class_alias( 'PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff' );
21+
}
22+
23+
define( 'PHPCS_ALIASES_SET', true );
24+
}

tests/fixtures/dummy-subdir/DummySubDir/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="DummySubDir" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
33

44
<description>Dummy PHPCS standard for testing.</description>
5+
6+
<autoload>/dummy-autoload.php</autoload>
57
</ruleset>

0 commit comments

Comments
 (0)