Skip to content

Commit

Permalink
PHPCS 3.x compat: remove test skipping for PHP 5.2
Browse files Browse the repository at this point in the history
Includes removal of two secondary test case files which were a work-around for unrecognized syntaxes in PHP 5.2.
  • Loading branch information
jrfnl committed Jul 25, 2017
1 parent ab7cbd9 commit ea76a40
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 186 deletions.
17 changes: 0 additions & 17 deletions WordPress/Tests/Classes/ClassInstantiationUnitTest.2.inc

This file was deleted.

17 changes: 0 additions & 17 deletions WordPress/Tests/Classes/ClassInstantiationUnitTest.2.inc.fixed

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ $b = & new Foobar();
// Currently not accounted for by the sniff, i.e. false negatives.
$a = new $$varHoldingClassName;
$a = new ${$varHoldingClassName};

// Namespaced classes: OK.
$a = new \MyClass();
$a = new \MyNamespace\MyClass();

// Namespaced classes: Bad.
$a = new \MyClass;
$a = new \MyNamespace\MyClass;
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ $b = & new Foobar();
// Currently not accounted for by the sniff, i.e. false negatives.
$a = new $$varHoldingClassName;
$a = new ${$varHoldingClassName};

// Namespaced classes: OK.
$a = new \MyClass();
$a = new \MyNamespace\MyClass();

// Namespaced classes: Bad.
$a = new \MyClass();
$a = new \MyNamespace\MyClass();
27 changes: 3 additions & 24 deletions WordPress/Tests/Classes/ClassInstantiationUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,6 @@
*/
class ClassInstantiationUnitTest extends AbstractSniffUnitTest {

/**
* Get a list of all test files to check.
*
* @param string $testFileBase The base path that the unit tests files will have.
*
* @return string[]
*/
protected function getTestFiles( $testFileBase ) {
$testFiles = parent::getTestFiles( $testFileBase );

if ( PHP_VERSION_ID < 50300 ) {
$testFiles = array_diff( $testFiles, array( $testFileBase . '2.inc' ) );
}

return $testFiles;
}

/**
* Returns the lines where errors should occur.
*
Expand All @@ -47,7 +30,7 @@ protected function getTestFiles( $testFileBase ) {
public function getErrorList( $testFile = '' ) {

switch ( $testFile ) {
case 'ClassInstantiationUnitTest.1.inc':
case 'ClassInstantiationUnitTest.inc':
return array(
37 => 1,
38 => 1,
Expand All @@ -70,12 +53,8 @@ public function getErrorList( $testFile = '' ) {
80 => 1,
84 => 1,
85 => 1,
);

case 'ClassInstantiationUnitTest.2.inc':
return array(
16 => 1,
17 => 1,
97 => 1,
98 => 1,
);

case 'ClassInstantiationUnitTest.js':
Expand Down
9 changes: 0 additions & 9 deletions WordPress/Tests/DB/RestrictedClassesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ protected function tearDown() {
parent::tearDown();
}

/**
* Skip this test on PHP 5.2 as otherwise testing the namespace resolving would fail.
*
* @return bool Whether to skip this test.
*/
protected function shouldSkipTest() {
return ( PHP_VERSION_ID < 50300 );
}

/**
* Returns the lines where errors should occur.
*
Expand Down
5 changes: 0 additions & 5 deletions WordPress/Tests/Files/FileNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ protected function getTestFiles( $testFileBase ) {
$sep = DIRECTORY_SEPARATOR;
$test_files = glob( dirname( $testFileBase ) . $sep . 'FileNameUnitTests{' . $sep . ',' . $sep . '*' . $sep . '}*.inc', GLOB_BRACE );

// Adjust the expected results array for PHP 5.2 as PHP 5.2 does not recognize namespaces.
if ( PHP_VERSION_ID < 50300 ) {
$this->expected_results['test-sample-phpunit6.inc'] = 1;
}

if ( ! empty( $test_files ) ) {
return $test_files;
}
Expand Down
21 changes: 1 addition & 20 deletions WordPress/Tests/NamingConventions/PrefixAllGlobalsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ public function getErrorList( $testFile = 'PrefixAllGlobalsUnitTest.inc' ) {
40 => 1,
90 => 1,
91 => 1,
// Scoped.
149 => ( PHP_VERSION_ID >= 50300 ) ? 0 : 1, // PHPCS on PHP 5.2 does not recognize namespaces.
151 => ( PHP_VERSION_ID >= 50300 ) ? 0 : 1, // PHPCS on PHP 5.2 does not recognize namespaces.
153 => ( PHP_VERSION_ID >= 50300 ) ? 0 : 1, // PHPCS on PHP 5.2 does not recognize namespaces.
154 => ( PHP_VERSION_ID >= 50300 ) ? 0 : 1, // PHPCS on PHP 5.2 does not recognize namespaces.
155 => ( PHP_VERSION_ID >= 50300 ) ? 0 : 1, // PHPCS on PHP 5.2 does not recognize namespaces.
// Backfills.
225 => ( function_exists( '\mb_strpos' ) ) ? 0 : 1,
230 => ( function_exists( '\array_column' ) ) ? 0 : 1,
Expand All @@ -66,20 +60,7 @@ public function getErrorList( $testFile = 'PrefixAllGlobalsUnitTest.inc' ) {
);

case 'PrefixAllGlobalsUnitTest.1.inc':
// Namespaced - all OK.
if ( PHP_VERSION_ID >= 50300 ) {
return array();
}

// PHPCS on PHP 5.2 does not recognize namespaces.
return array(
9 => 1,
11 => 1,
13 => 1,
14 => 1,
15 => 1,
);

// Namespaced - all OK, fall through to the default case.
default:
return array();

Expand Down
8 changes: 4 additions & 4 deletions WordPress/Tests/VIP/AdminBarRemovalUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function getErrorList( $testFile = '' ) {
21 => 1,
26 => 1,
32 => 1,
56 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize T_NOWDOC.
57 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize T_NOWDOC.
58 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize T_NOWDOC.
56 => 1,
57 => 1,
58 => 1,
68 => 1,
69 => 1,
70 => 1,
Expand All @@ -60,7 +60,7 @@ public function getErrorList( $testFile = '' ) {

case 'AdminBarRemovalUnitTest.css':
return array(
15 => 1,
15 => 1,
16 => 1,
17 => 1,
22 => 1,
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Tests/VIP/DirectDatabaseQueryUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getErrorList() {
190 => 1,
250 => 1,
257 => 1,
274 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize T_NOWDOC.
274 => 1,
);

}
Expand Down
7 changes: 3 additions & 4 deletions WordPress/Tests/VIP/PluginMenuSlugUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ class PluginMenuSlugUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
5 => 1,
9 => 2,
14 => ( PHP_VERSION_ID < 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize T_NS_SEPARATOR.
3 => 1,
5 => 1,
9 => 2,
);

}
Expand Down
1 change: 0 additions & 1 deletion WordPress/Tests/VIP/RestrictedFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public function getErrorList() {
return array(
3 => 1,
17 => 1,
30 => ( PHP_VERSION_ID >= 50300 ) ? 0 : 1,
32 => 1,
34 => 1,
36 => 1,
Expand Down
10 changes: 0 additions & 10 deletions WordPress/Tests/WP/CapitalPDangitUnitTest.1.inc

This file was deleted.

6 changes: 6 additions & 0 deletions WordPress/Tests/WP/CapitalPDangitUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,9 @@ echo 'This is an explanation about wordpress.'; // WPCS: spelling ok.

<?php // POT filename should be ignored. ?>
wordpress.pot

<?php
// Bad.
$text = <<<'EOD'
This is an explanation about word-press.
EOD;
6 changes: 6 additions & 0 deletions WordPress/Tests/WP/CapitalPDangitUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,9 @@ echo 'This is an explanation about wordpress.'; // WPCS: spelling ok.

<?php // POT filename should be ignored. ?>
wordpress.pot

<?php
// Bad.
$text = <<<'EOD'
This is an explanation about WordPress.
EOD;
63 changes: 26 additions & 37 deletions WordPress/Tests/WP/CapitalPDangitUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,36 @@ public function getErrorList() {
/**
* Returns the lines where warnings should occur.
*
* @param string $testFile The name of the file being tested.
* @return array <int line number> => <int number of warnings>
*/
public function getWarningList( $testFile = 'CapitalPDangitUnitTest.inc' ) {
public function getWarningList() {

switch ( $testFile ) {
case 'CapitalPDangitUnitTest.inc':
return array(
3 => 1,
5 => 1,
8 => 1,
26 => 1,
28 => 1,
34 => 1,
35 => 1,
36 => 1,
40 => 1,
41 => 1,
45 => 1,
53 => 1,
60 => 1,
61 => 1,
62 => 1,
65 => 1,
66 => 1,
68 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 2, // PHPCS on PHP 5.2 apparently breaks the token up into two tokens.
101 => 1,
139 => 1,
146 => 0, // False negative.
173 => 1,
);
return array(
3 => 1,
5 => 1,
8 => 1,
26 => 1,
28 => 1,
34 => 1,
35 => 1,
36 => 1,
40 => 1,
41 => 1,
45 => 1,
53 => 1,
60 => 1,
61 => 1,
62 => 1,
65 => 1,
66 => 1,
68 => 1,
101 => 1,
139 => 1,
146 => 0, // False negative.
173 => 1,
181 => 1,
);

case 'CapitalPDangitUnitTest.1.inc':
return array(
9 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize nowdocs.
);

default:
return array();

} // End switch().
}

} // End class.
12 changes: 6 additions & 6 deletions WordPress/Tests/WP/EnqueuedResourcesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class EnqueuedResourcesUnitTest extends AbstractSniffUnitTest {
public function getErrorList() {
return array(
1 => 1,
2 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 has a bug tokenizing inline HTML / `<s`.
2 => 1,
6 => 1,
7 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 has a bug tokenizing inline HTML / `<s`.
7 => 1,
10 => 1,
11 => 1,
13 => 1,
Expand All @@ -40,10 +40,10 @@ public function getErrorList() {
17 => 1,
20 => 1,
21 => 1,
25 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize double quoted T_HEREDOC.
26 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize double quoted T_HEREDOC.
30 => 1, // PHPCS on PHP 5.2 does not recognize T_NOWDOC, but sees this as a literal string anyway.
31 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 0, // PHPCS on PHP 5.2 does not recognize T_NOWDOC.
25 => 1,
26 => 1,
30 => 1,
31 => 1,
);

}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Tests/WP/I18nUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getErrorList( $testFile = 'I18nUnitTest.inc' ) {
125 => 1,
128 => 1,
129 => 1,
132 => ( PHP_VERSION_ID >= 50300 ) ? 1 : 2, // PHPCS on PHP 5.2 does not recognize T_NOWDOC.
132 => 1,
138 => 1,
143 => 1,
148 => 1,
Expand Down
19 changes: 1 addition & 18 deletions WordPress/Tests/WP/PreparedSQLUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PreparedSQLUnitTest extends AbstractSniffUnitTest {
* @return array <int line number> => <int number of errors>
*/
public function getErrorList() {
$errors = array(
return array(
3 => 1,
4 => 1,
5 => 1,
Expand All @@ -44,23 +44,6 @@ public function getErrorList() {
64 => 1,
71 => 1,
);

// Deal with PHP 5.2 not recognizing quoted heredoc openers, nor nowdoc syntax.
// These are all false positives!
if ( PHP_VERSION_ID < 50300 ) {
$errors[68] = 2;
$errors[69] = 2;
$errors[70] = 2;
$errors[71] = 4;
$errors[75] = 2;
$errors[76] = 7;
$errors[77] = 4;
$errors[78] = 5;
$errors[79] = 7;
$errors[80] = 1;
}

return $errors;
}

/**
Expand Down
Loading

0 comments on commit ea76a40

Please sign in to comment.