diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc b/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc index 4449a0395..d41ff8637 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc @@ -30,7 +30,7 @@ class MyMysqli extends mysqli {} class YourMysqli extends \mysqli {} class OurMysqli implements mysqli {} -class TheirMysqli implements \mysqli {} +class TheirMysqli implements \MYSQLI {} $db5 = new PDO(); $db6 = ( new PDO() )->exec(); @@ -115,3 +115,24 @@ $anon = new readonly class { $anon = new readonly class() extends PDOStatement {}; // Error. $anon = new #[MyAttribute] readonly class {}; + +/* + * Safeguard correct handling of namespaced class references (the namespace types not handled below are already handled + * in other tests above). + */ +$obj = new MyNamespace\PDO(); +$obj = new \MyNamespace\PDOStatement(); +$obj = new namespace\Sub\mysqli(); +$obj = new namespace\PDO(); // Error. +class MyClass1 extends MyNamespace\mysqli {} +class MyClass2 extends \MyNamespace\PDO {} +class MyClass3 extends namespace\Sub\PDOStatement {} +class MyClass4 extends namespace\mysqli {} // Error. +class MyClass5 implements MyNamespace\mysqli {} +class MyClass6 implements \MyNamespace\PDO {} +class MyClass7 implements namespace\Sub\PDOStatement {} +class MyClass8 implements namespace\mysqli {} // Error. +MyNamespace\mysqli::do_something(); +\MyNamespace\PDO::do_something(); +namespace\Sub\PDOStatement::do_something(); +namespace\MYSQLI::do_something(); // Error. diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.php b/WordPress/Tests/DB/RestrictedClassesUnitTest.php index a07ace04d..a9bb96546 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.php +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.php @@ -102,6 +102,10 @@ public function getErrorList( $testFile = '' ) { 103 => 1, 106 => 1, 115 => 1, + 126 => 1, + 130 => 1, + 134 => 1, + 138 => 1, ); case 'RestrictedClassesUnitTest.2.inc': diff --git a/WordPress/Tests/WP/ClassNameCaseUnitTest.inc b/WordPress/Tests/WP/ClassNameCaseUnitTest.inc index 1c540dc65..70af2b148 100644 --- a/WordPress/Tests/WP/ClassNameCaseUnitTest.inc +++ b/WordPress/Tests/WP/ClassNameCaseUnitTest.inc @@ -65,3 +65,29 @@ class NotYetDetected { public function paramTypeDeclaration( wp_role $role ) {} public function returnTypeDeclaration() : WP_TERM {} } + +class ImplementsInterfaceCorrectCase implements SimplePie_Cache_Base {} +class ImplementsInterfaceIncorrectCase implements simplepie_cache_base {} + +/* + * Safeguard correct handling of namespaced class references (the namespace types not handled below are already handled + * in other tests above). + */ +$obj = new MyNamespace\atomEntry(); +$obj = new \MyNamespace\core_upgrader(); +$obj = new namespace\Sub\file_upload_upgrader(); +$obj = new namespace\pop3(); // Warning. +class MyClass1 extends MyNamespace\twentytwenty_walker_page {} +class MyClass2 extends \MyNamespace\TWENTY_ELEVEN_EPHEMERA_WIDGET {} +class MyClass3 extends namespace\Sub\twenty_Twenty_One_SVG_icons {} +class MyClass4 extends namespace\twentynineteen_SVG_icons {} // Warning. +class MyClass5 implements \WPORG\REQUESTS\AUTH {} // Warning. +class MyClass6 implements \MyNamespace\SIMPLEPIE\Cache\namefilter {} +class MyClass7 implements MyNamespace\requests_auth {} +class MyClass8 implements namespace\Sub\WpOrg\REQUESTS\proxy {} +class MyClass9 implements namespace\simplepie\CACHE\base {} // Warning. +\avifinfo\Box::prepare_query(); // Warning. +MyNamespace\Avifinfo\CHAN_PROP::prepare_query(); +\MyNamespace\Avifinfo\features::prepare_query(); +namespace\Sub\AVIFINFO\parser::prepare_query(); +namespace\AVIFINFO\TILE::prepare_query(); // Warning. diff --git a/WordPress/Tests/WP/ClassNameCaseUnitTest.php b/WordPress/Tests/WP/ClassNameCaseUnitTest.php index 7869ea7f6..62f9f6b17 100644 --- a/WordPress/Tests/WP/ClassNameCaseUnitTest.php +++ b/WordPress/Tests/WP/ClassNameCaseUnitTest.php @@ -45,6 +45,13 @@ public function getWarningList() { 47 => 1, 48 => 1, 49 => 1, + 70 => 1, + 79 => 1, + 83 => 1, + 84 => 1, + 88 => 1, + 89 => 1, + 93 => 1, ); } } diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.inc b/WordPress/Tests/WP/DeprecatedClassesUnitTest.1.inc similarity index 100% rename from WordPress/Tests/WP/DeprecatedClassesUnitTest.inc rename to WordPress/Tests/WP/DeprecatedClassesUnitTest.1.inc diff --git a/WordPress/Tests/WP/DeprecatedClassesUnitTest.2.inc b/WordPress/Tests/WP/DeprecatedClassesUnitTest.2.inc new file mode 100644 index 000000000..6b710f9d2 --- /dev/null +++ b/WordPress/Tests/WP/DeprecatedClassesUnitTest.2.inc @@ -0,0 +1,23 @@ + Key is the line number, value is the number of expected errors. */ - public function getErrorList() { - $start_line = 9; - $end_line = 28; - $errors = array_fill( $start_line, ( ( $end_line - $start_line ) + 1 ), 1 ); + public function getErrorList( $testFile = '' ) { + switch ( $testFile ) { + case 'DeprecatedClassesUnitTest.1.inc': + $start_line = 9; + $end_line = 28; + $errors = array_fill( $start_line, ( ( $end_line - $start_line ) + 1 ), 1 ); + + // Unset the lines related to version comments. + unset( $errors[16], $errors[18], $errors[21], $errors[26] ); + + return $errors; - // Unset the lines related to version comments. - unset( $errors[16], $errors[18], $errors[21], $errors[26] ); + case 'DeprecatedClassesUnitTest.2.inc': + return array( + 9 => 1, + 13 => 1, + 14 => 1, + 18 => 1, + 19 => 1, + 23 => 1, + ); - return $errors; + default: + return array(); + } } /**