diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc index bb976bf8fe..e862f6935c 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc @@ -94,3 +94,11 @@ WP_Date_Query::build_mysql_datetime(); // Ok. myFictionFunction(); // Bad. myFictional(); // OK. Myfictional(); // OK. + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\mysql_connect(); +MyNamespace\mysql_connect(); +\MyNamespace\mysql_connect(); +namespace\mysql_connect(); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php index 73702af626..597dc20d66 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php @@ -68,54 +68,56 @@ protected function resetGroups() { */ public function getErrorList() { return array( - 25 => 1, - 26 => 1, - 27 => 1, - 28 => 1, - 29 => 1, - 30 => 1, - 31 => 1, - 32 => 1, - 33 => 1, - - 36 => 1, - 37 => 1, - 38 => 1, - 39 => 1, - 40 => 1, - 41 => 1, - 42 => 1, - 43 => 1, - 44 => 1, - - 47 => 1, - 48 => 1, - 49 => 1, - 50 => 1, - 51 => 1, - - 54 => 1, - 55 => 1, - 56 => 1, - 57 => 1, - - 60 => 1, - - 63 => 1, - - 66 => 1, - 67 => 1, - 68 => 1, - 69 => 1, - 70 => 1, - 71 => 1, - 72 => 1, - 73 => 1, - 74 => 1, - 75 => 1, - 76 => 1, - - 94 => 1, + 25 => 1, + 26 => 1, + 27 => 1, + 28 => 1, + 29 => 1, + 30 => 1, + 31 => 1, + 32 => 1, + 33 => 1, + + 36 => 1, + 37 => 1, + 38 => 1, + 39 => 1, + 40 => 1, + 41 => 1, + 42 => 1, + 43 => 1, + 44 => 1, + + 47 => 1, + 48 => 1, + 49 => 1, + 50 => 1, + 51 => 1, + + 54 => 1, + 55 => 1, + 56 => 1, + 57 => 1, + + 60 => 1, + + 63 => 1, + + 66 => 1, + 67 => 1, + 68 => 1, + 69 => 1, + 70 => 1, + 71 => 1, + 72 => 1, + 73 => 1, + 74 => 1, + 75 => 1, + 76 => 1, + + 94 => 1, + + 101 => 1, ); } diff --git a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc index 25227b5178..4c3a6d11bc 100644 --- a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc +++ b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc @@ -7,3 +7,11 @@ $date->setTimezone( new DateTimeZone( 'America/Toronto' ) ); // Yay! $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), date( __( 'F j, Y' ), $now ), date( __( 'g:i a' ), $now ) ); // Error. $post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) ); // OK. + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\date_default_timezone_set( 'Foo/Bar' ); +MyNamespace\date_default_timezone_set( 'Foo/Bar' ); +\MyNamespace\date_default_timezone_set( 'Foo/Bar' ); +namespace\date_default_timezone_set( 'Foo/Bar' ); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php index f5e160bc62..a2f29c2364 100644 --- a/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php @@ -27,8 +27,9 @@ final class RestrictedFunctionsUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { return array( - 3 => 1, - 8 => 2, + 3 => 1, + 8 => 2, + 14 => 1, ); } diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc index b07e7a8ce6..fec3eaa978 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc @@ -35,5 +35,11 @@ phpinfo(); // Error. Wrapper_Class::var_dump(); // OK, not the native PHP function. $wrapper ->var_dump(); // OK, not the native PHP function. -namespace\var_dump(); // OK as long as the file is namespaced. -MyNamespace\var_dump(); // OK, namespaced function. + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\var_dump( $value ); +MyNamespace\var_dump( $value ); +\MyNamespace\var_dump( $value ); +namespace\var_dump( $value ); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php index 8be090a5bf..f3e953545c 100644 --- a/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php @@ -52,6 +52,7 @@ public function getWarningList() { 24 => 1, 33 => 1, 34 => 1, + 42 => 1, ); } } diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc index 9a17c8a6d8..7049336d73 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc @@ -41,3 +41,11 @@ $handle = popen( '/bin/ls', 'r' ); // Issue #898. class System {} class Serialize {} + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\serialize( $value ); +MyNamespace\serialize( $value ); +\MyNamespace\serialize( $value ); +namespace\serialize( $value ); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php index ee28c4fe42..5084e05911 100644 --- a/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php @@ -60,6 +60,7 @@ public function getWarningList() { 37 => 1, 38 => 1, 39 => 1, + 48 => 1, ); } } diff --git a/WordPress/Tests/PHP/DontExtractUnitTest.inc b/WordPress/Tests/PHP/DontExtractUnitTest.inc index 9ed5c3d2b2..ea5b9dfcec 100644 --- a/WordPress/Tests/PHP/DontExtractUnitTest.inc +++ b/WordPress/Tests/PHP/DontExtractUnitTest.inc @@ -7,3 +7,11 @@ my_extract(); // Ok. My_Object::extract(); // Ok. $this->extract(); // Ok. $my_object->extract(); // Ok. + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\extract( array( 'a' => 1 ) ); +MyNamespace\extract( array( 'a' => 1 ) ); +\MyNamespace\extract( array( 'a' => 1 ) ); +namespace\extract( array( 'a' => 1 ) ); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/PHP/DontExtractUnitTest.php b/WordPress/Tests/PHP/DontExtractUnitTest.php index 3efee7c9a8..f9a1df7494 100644 --- a/WordPress/Tests/PHP/DontExtractUnitTest.php +++ b/WordPress/Tests/PHP/DontExtractUnitTest.php @@ -29,7 +29,8 @@ final class DontExtractUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { return array( - 3 => 1, + 3 => 1, + 14 => 1, ); } diff --git a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc index 785779e02b..34e0de6722 100644 --- a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc @@ -24,3 +24,11 @@ list( $year, $month, $day ) = split( ':', $date ); // Bad, split has been deprec $title_parts = spliti( ' ', get_the_title(), 4 ); // Bad, spliti also deprecated. Use preg_split instead. sql_regcase( 'Foo - bar.'); // Bad. Deprecated. + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\split( ':', $date ); +MyNamespace\split( ':', $date ); +\MyNamespace\split( ':', $date ); +namespace\split( ':', $date ); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php index 7dbfcd6100..d4086c3e49 100644 --- a/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/POSIXFunctionsUnitTest.php @@ -35,6 +35,7 @@ public function getErrorList() { 22 => 1, 24 => 1, 26 => 1, + 31 => 1, ); } diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc index 84dbd1d7b3..3edf622b1a 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc @@ -3,3 +3,11 @@ add_action( 'widgets_init', create_function( '', // Error. 'return register_widget( "time_more_on_time_widget" );' ) ); + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\create_function('', 'return;'); +MyNamespace\create_function('', 'return;'); +\MyNamespace\create_function('', 'return;'); +namespace\create_function('', 'return;'); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php index d930ba4329..5cfa75ae51 100644 --- a/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php +++ b/WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php @@ -27,7 +27,8 @@ final class RestrictedPHPFunctionsUnitTest extends AbstractSniffUnitTest { */ public function getErrorList() { return array( - 3 => 1, + 3 => 1, + 10 => 1, ); } diff --git a/WordPress/Tests/Security/SafeRedirectUnitTest.inc b/WordPress/Tests/Security/SafeRedirectUnitTest.inc index 690fbe70f0..bbdc66b314 100644 --- a/WordPress/Tests/Security/SafeRedirectUnitTest.inc +++ b/WordPress/Tests/Security/SafeRedirectUnitTest.inc @@ -2,3 +2,11 @@ wp_redirect( $location ); // Warning. wp_safe_redirect( $location ); // OK. + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\wp_redirect( $location ); +MyNamespace\wp_redirect( $location ); +\MyNamespace\wp_redirect( $location ); +namespace\wp_redirect( $location ); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/Security/SafeRedirectUnitTest.php b/WordPress/Tests/Security/SafeRedirectUnitTest.php index b62e6f86c8..358cdcfdd1 100644 --- a/WordPress/Tests/Security/SafeRedirectUnitTest.php +++ b/WordPress/Tests/Security/SafeRedirectUnitTest.php @@ -37,6 +37,7 @@ public function getErrorList() { public function getWarningList() { return array( 3 => 1, + 9 => 1, ); } } diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc index a88e5638a9..3336dd0b18 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc @@ -147,3 +147,11 @@ file_get_contents( // Not using plugin_dir_path() for reasons. $url ); // Warning. + +/* + * Safeguard support for PHP 8.0+ tokenization of namespaced "names". + */ +\curl_init(); +MyNamespace\curl_init(); +\MyNamespace\curl_init(); +namespace\curl_init(); // The sniff should start flagging this once it can resolve relative namespaces. diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php index b0f1bf96aa..e660886adb 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php @@ -89,6 +89,7 @@ public function getWarningList() { 131 => 1, 142 => 1, 146 => 1, + 154 => 1, ); } } diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.1.inc similarity index 100% rename from WordPress/Tests/WP/DeprecatedFunctionsUnitTest.inc rename to WordPress/Tests/WP/DeprecatedFunctionsUnitTest.1.inc diff --git a/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc new file mode 100644 index 0000000000..936b2b94f4 --- /dev/null +++ b/WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc @@ -0,0 +1,9 @@ + Key is the line number, value is the number of expected errors. */ - public function getErrorList() { - $start_line = 8; - $end_line = 420; - $errors = array_fill( $start_line, ( ( $end_line - $start_line ) + 1 ), 1 ); + public function getErrorList( $testFile = '' ) { + switch ( $testFile ) { + case 'DeprecatedFunctionsUnitTest.1.inc': + $start_line = 8; + $end_line = 420; + $errors = array_fill( $start_line, ( ( $end_line - $start_line ) + 1 ), 1 ); + + // Unset the lines related to version comments. + unset( + $errors[10], + $errors[12], + $errors[14], + $errors[16], + $errors[29], + $errors[55], + $errors[57], + $errors[59], + $errors[73], + $errors[76], + $errors[80], + $errors[102], // Undeprecated function. + $errors[118], + $errors[125], + $errors[162], + $errors[175], + $errors[179], + $errors[211], + $errors[234], + $errors[252], + $errors[256], + $errors[263], + $errors[275], + $errors[282], + $errors[286], + $errors[291], + $errors[296], + $errors[304], + $errors[311], + $errors[319], + $errors[323], + $errors[330], + $errors[332], + $errors[337], + $errors[340], + $errors[344], + $errors[346], + $errors[353], + $errors[357], + $errors[359], + $errors[361], + $errors[363], + $errors[369], + $errors[371], + $errors[373], + $errors[383], + $errors[386], + $errors[410] + ); + + return $errors; - // Unset the lines related to version comments. - unset( - $errors[10], - $errors[12], - $errors[14], - $errors[16], - $errors[29], - $errors[55], - $errors[57], - $errors[59], - $errors[73], - $errors[76], - $errors[80], - $errors[102], // Undeprecated function. - $errors[118], - $errors[125], - $errors[162], - $errors[175], - $errors[179], - $errors[211], - $errors[234], - $errors[252], - $errors[256], - $errors[263], - $errors[275], - $errors[282], - $errors[286], - $errors[291], - $errors[296], - $errors[304], - $errors[311], - $errors[319], - $errors[323], - $errors[330], - $errors[332], - $errors[337], - $errors[340], - $errors[344], - $errors[346], - $errors[353], - $errors[357], - $errors[359], - $errors[361], - $errors[363], - $errors[369], - $errors[371], - $errors[373], - $errors[383], - $errors[386], - $errors[410] - ); + case 'DeprecatedFunctionsUnitTest.2.inc': + return array( + 6 => 1, + ); - return $errors; + default: + return array(); + } } /** * Returns the lines where warnings should occur. * + * @param string $testFile The test file to check for warnings. + * * @return array Key is the line number, value is the number of expected warnings. */ - public function getWarningList() { - $start_line = 426; - $end_line = 443; - $warnings = array_fill( $start_line, ( ( $end_line - $start_line ) + 1 ), 1 ); + public function getWarningList( $testFile = '' ) { + switch ( $testFile ) { + case 'DeprecatedFunctionsUnitTest.1.inc': + $start_line = 426; + $end_line = 443; + $warnings = array_fill( $start_line, ( ( $end_line - $start_line ) + 1 ), 1 ); + + // Unset the lines related to version comments. + unset( + $warnings[429], + $warnings[432], + $warnings[442] + ); - // Unset the lines related to version comments. - unset( - $warnings[429], - $warnings[432], - $warnings[442] - ); + return $warnings; - return $warnings; + default: + return array(); + } } } diff --git a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.inc b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.inc index 5e952933d2..66a33f4984 100644 --- a/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/DiscouragedFunctionsUnitTest.inc @@ -14,8 +14,8 @@ $obj?->query_posts(); // OK, not the global function. // Ensure the sniff doesn't act on namespaced calls. MyNamespace\query_posts(); // OK, not the global function. +\MyNamespace\query_posts(); // OK, not the global function. namespace\query_posts(); // OK, not the global function. - // ... but does act on fully qualified function calls. \query_posts(); // Warning.