Skip to content

Commit dfe6a2c

Browse files
committed
Classes/RestrictedExtendClasses: improve the tests
Add tests with: * Variations of namespaced class names. * Anonymous classes extending. * Group exclusion, as supported via the extended abstract.
1 parent 05a0547 commit dfe6a2c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

WordPressVIPMinimum/Tests/Classes/RestrictedExtendClassesUnitTest.inc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
class OkTestClass extends WPCOM_VIP_CLI_Command { } // Ok - correct class.
44
class AnotherOkTestClass extends WPC__CLI_Command { } // Ok - spacing + similar class.
5-
class Ok_TestClass extends wpcom_vip_cli_command { } // Ok - lowercase correct class.
6-
class Ok_Test_Class extends WpCoM_VIP_cli_command { } // Ok - mixed case correct class.
5+
class Ok_TestClass extends \wpcom_vip_cli_command { } // Ok - lowercase correct class.
6+
$ok = new class extends WpCoM_VIP_cli_command { }; // Ok - mixed case correct class.
77
class WP_CLI_Command { } // Ok - not extending.
88

99
class BadTestClass extends WP_CLI_Command { } // Warning - wrong class.
10-
class AnotherBadTestClass extends wp_CLI_comMand { } // Warning - mixed case wrong class.
11-
class AnotherBad_TestClass extends WP_CLI_comMand { } // Warning - spacing + mixed case wrong class.
10+
class AnotherBadTestClass extends \wp_CLI_comMand { } // Warning - mixed case wrong class.
11+
$bad = new class() extends WP_CLI_comMand { }; // Warning - spacing + mixed case wrong class.
1212
class Bad_Test_Class extends wp_cli_command { } // Warning - lowercase wrong class.
13+
14+
// phpcs:set WordPressVIPMinimum.Classes.RestrictedExtendClasses exclude[] wp_cli
15+
class IgnoredClass extends WP_CLI_Command { } // OK, group is excluded.
16+
17+
// Reset to the default value.
18+
// phpcs:set WordPressVIPMinimum.Classes.RestrictedExtendClasses exclude[]
19+
20+
class Ok_NotTheTargetFQN extends \Fully\Qualified\WP_CLI_Command { } // Ok - not the right namespace.
21+
class Ok_NotTheTargetPQN extends Partially\Qualified\WP_CLI_Command { } // Ok - not the right namespace.
22+
class Bad_NamespaceRelative extends namespace\WP_CLI_Command { } // Warning - this is not a namespaced file, so "namespace" resolves to the global namespace.

WordPressVIPMinimum/Tests/Classes/RestrictedExtendClassesUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function getWarningList() {
3636
10 => 1,
3737
11 => 1,
3838
12 => 1,
39+
22 => 1,
3940
];
4041
}
4142
}

0 commit comments

Comments
 (0)