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
19 changes: 18 additions & 1 deletion WordPress/Tests/DB/RestrictedClassesUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -115,3 +115,20 @@ $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();
class MyClass1 extends MyNamespace\mysqli {}
class MyClass2 extends \MyNamespace\PDO {}
class MyClass3 extends namespace\Sub\PDOStatement {}
class MyClass4 extends namespace\mysqli {}
MyNamespace\mysqli::do_something();
\MyNamespace\PDO::do_something();
namespace\Sub\PDOStatement::do_something();
namespace\MYSQLI::do_something();
3 changes: 3 additions & 0 deletions WordPress/Tests/DB/RestrictedClassesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public function getErrorList( $testFile = '' ) {
103 => 1,
106 => 1,
115 => 1,
126 => 1,
130 => 1,
134 => 1,
);

case 'RestrictedClassesUnitTest.2.inc':
Expand Down
18 changes: 18 additions & 0 deletions WordPress/Tests/WP/ClassNameCaseUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,21 @@ class NotYetDetected {
public function paramTypeDeclaration( wp_role $role ) {}
public function returnTypeDeclaration() : WP_TERM {}
}

/*
* 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();
class MyClass2 extends MyNamespace\twentytwenty_walker_page {}
class MyClass3 extends \MyNamespace\TWENTY_ELEVEN_EPHEMERA_WIDGET {}
class MyClass4 extends namespace\Sub\twenty_Twenty_One_SVG_icons {}
class MyClass5 extends namespace\twentynineteen_SVG_icons {}
\avifinfo\Box::prepare_query();
MyNamespace\Avifinfo\CHAN_PROP::prepare_query();
\MyNamespace\Avifinfo\features::prepare_query();
namespace\Sub\AVIFINFO\parser::prepare_query();
namespace\AVIFINFO\TILE::prepare_query();
4 changes: 4 additions & 0 deletions WordPress/Tests/WP/ClassNameCaseUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function getWarningList() {
47 => 1,
48 => 1,
49 => 1,
76 => 1,
80 => 1,
81 => 1,
85 => 1,
);
}
}
20 changes: 20 additions & 0 deletions WordPress/Tests/WP/DeprecatedClassesUnitTest.2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* Safeguard correct handling of all types of namespaced class name references.
*/
$streams = new \WP_User_Search();
$streams = new MyNamespace\WP_HTTP_Fsockopen();
$streams = new \MyNamespace\WP_Customize_New_Menu_Section();
$streams = new namespace\Sub\WP_Customize_New_Menu_Control();
$streams = new namespace\WP_Privacy_Data_Export_Requests_Table();
class MyClass1 extends \WP_Privacy_Data_Removal_Requests_Table {}
class MyClass2 extends MyNamespace\Services_JSON {}
class MyClass3 extends \MyNamespace\Services_JSON_Error {}
class MyClass4 extends namespace\Sub\WP_Http_Curl {}
class MyClass5 extends namespace\WP_Http_Streams {}
\wp_user_search::do_something();
MyNamespace\WP_HTTP_Fsockopen::do_something();
\MyNamespace\WP_Customize_New_Menu_Section::do_something();
namespace\Sub\WP_Customize_New_Menu_Control::do_something();
namespace\WP_PRIVACY_DATA_EXPORT_REQUESTS_TABLE::do_something();
32 changes: 25 additions & 7 deletions WordPress/Tests/WP/DeprecatedClassesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,35 @@ final class DeprecatedClassesUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @param string $testFile The test file to check for errors.
*
* @return array<int, int> 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(
6 => 1,
10 => 1,
11 => 1,
15 => 1,
16 => 1,
20 => 1,
);

return $errors;
default:
return array();
}
}

/**
Expand Down
Loading