Skip to content

Commit d886846

Browse files
committed
WP/CapitalPDangit: add tests using typed class constants
This commit adds a few tests using type class constants to the `WordPress.WP.CapitalPDangit` tests. This is just to ensure that the part of the sniff code that checks for `T_CONST` tokens to ignore constant declarations using the `const` keyword works correctly with typed class constants added in PHP 8.3. The sniff was already handling typed class constants correctly, and no change to the sniff code is needed.
1 parent 17e801e commit d886846

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

WordPress/Tests/WP/CapitalPDangitUnitTest.1.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,16 @@ echo Some\Enum\WordPress::ENUM_CONSTANT;
231231

232232
// Safeguard that the sniff doesn't act on anonymous classes.
233233
$anon = new class() {};
234+
235+
/*
236+
* Safeguard that PHP 8.3+ typed class constants are handled correctly.
237+
*/
238+
class TypeClassConstants {
239+
public const string WORDPRESS = 'wordress';
240+
241+
public const ?string ANOTHER = 'value',
242+
WORDPRESS_SOMETHING = 'wordpress';
243+
244+
// Ensures no false positives on incorrect casing in a class constant type name.
245+
public const (\Fully\Qualified\MyClass&wordPRESS)|string ANOTHER_WORDPRESS = 'wordpress';
246+
}

WordPress/Tests/WP/CapitalPDangitUnitTest.1.inc.fixed

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,16 @@ echo Some\Enum\WordPress::ENUM_CONSTANT;
231231

232232
// Safeguard that the sniff doesn't act on anonymous classes.
233233
$anon = new class() {};
234+
235+
/*
236+
* Safeguard that PHP 8.3+ typed class constants are handled correctly.
237+
*/
238+
class TypeClassConstants {
239+
public const string WORDPRESS = 'wordress';
240+
241+
public const ?string ANOTHER = 'value',
242+
WORDPRESS_SOMETHING = 'wordpress';
243+
244+
// Ensures no false positives on incorrect casing in a class constant type name.
245+
public const (\Fully\Qualified\MyClass&wordPRESS)|string ANOTHER_WORDPRESS = 'wordpress';
246+
}

0 commit comments

Comments
 (0)