Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
98 changes: 50 additions & 48 deletions WordPress/Tests/DB/RestrictedFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 3 additions & 2 deletions WordPress/Tests/DateTime/RestrictedFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ final class RestrictedFunctionsUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
8 => 2,
3 => 1,
8 => 2,
14 => 1,
);
}

Expand Down
10 changes: 8 additions & 2 deletions WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions WordPress/Tests/PHP/DevelopmentFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function getWarningList() {
24 => 1,
33 => 1,
34 => 1,
42 => 1,
);
}
}
8 changes: 8 additions & 0 deletions WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ $handle = popen( '/bin/ls', 'r' );
// Issue #898.
class System {}
class Serialize {}

/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these tests have re-used the currently empty block of lines at the top of the file ?

* 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.
1 change: 1 addition & 0 deletions WordPress/Tests/PHP/DiscouragedPHPFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function getWarningList() {
37 => 1,
38 => 1,
39 => 1,
48 => 1,
);
}
}
8 changes: 8 additions & 0 deletions WordPress/Tests/PHP/DontExtractUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion WordPress/Tests/PHP/DontExtractUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ final class DontExtractUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
3 => 1,
14 => 1,
);
}

Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions WordPress/Tests/PHP/POSIXFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function getErrorList() {
22 => 1,
24 => 1,
26 => 1,
31 => 1,
);
}

Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion WordPress/Tests/PHP/RestrictedPHPFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ final class RestrictedPHPFunctionsUnitTest extends AbstractSniffUnitTest {
*/
public function getErrorList() {
return array(
3 => 1,
3 => 1,
10 => 1,
);
}

Expand Down
8 changes: 8 additions & 0 deletions WordPress/Tests/Security/SafeRedirectUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions WordPress/Tests/Security/SafeRedirectUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function getErrorList() {
public function getWarningList() {
return array(
3 => 1,
9 => 1,
);
}
}
8 changes: 8 additions & 0 deletions WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests need to be expanded a lot more.

This sniff also looks at the parameters for a number of target functions and for those check for certain (global) constants and/or function calls in the parameters, so tests are needed to cover those being fully qualified as well.

1 change: 1 addition & 0 deletions WordPress/Tests/WP/AlternativeFunctionsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function getWarningList() {
131 => 1,
142 => 1,
146 => 1,
154 => 1,
);
}
}
9 changes: 9 additions & 0 deletions WordPress/Tests/WP/DeprecatedFunctionsUnitTest.2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

/*
* Safeguard support for PHP 8.0+ tokenization of namespaced "names".
*/
\the_category_ID();
MyNamespace\the_category_ID();
\MyNamespace\the_category_ID();
namespace\the_category_ID(); // The sniff should start flagging this once it can resolve relative namespaces.
Loading
Loading