Skip to content

Commit f7ad0f3

Browse files
committed
Univeral/[Disallow|Require]AnonClassParentheses: add tests with anon classes with attributes
1 parent 1f438a4 commit f7ad0f3

6 files changed

+50
-0
lines changed

Universal/Tests/Classes/DisallowAnonClassParenthesesUnitTest.1.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ $anon = new class // Comment
2626

2727
$b = new class ( /*comment*/ ) {};
2828

29+
/*
30+
* Safeguard handling of anon classes with attributes.
31+
*/
32+
$anon = new
33+
#[AllowDynamicProperties]
34+
#[MyAttribute, AnotherAttribute]
35+
class() {}; // Bad.
36+
37+
$anon = new
38+
#[MyAttribute, AnotherAttribute]
39+
class {}; // OK.
40+
2941
// Live coding.
3042
// Intentional parse error. This has to be the last test in the file.
3143
$anon = new class()

Universal/Tests/Classes/DisallowAnonClassParenthesesUnitTest.1.inc.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ $anon = new class // Comment
2626

2727
$b = new class /*comment*/ {};
2828

29+
/*
30+
* Safeguard handling of anon classes with attributes.
31+
*/
32+
$anon = new
33+
#[AllowDynamicProperties]
34+
#[MyAttribute, AnotherAttribute]
35+
class {}; // Bad.
36+
37+
$anon = new
38+
#[MyAttribute, AnotherAttribute]
39+
class {}; // OK.
40+
2941
// Live coding.
3042
// Intentional parse error. This has to be the last test in the file.
3143
$anon = new class()

Universal/Tests/Classes/DisallowAnonClassParenthesesUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function getErrorList($testFile = '')
3838
23 => 1,
3939
24 => 1,
4040
27 => 1,
41+
35 => 1,
4142
];
4243

4344
default:

Universal/Tests/Classes/RequireAnonClassParenthesesUnitTest.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ $anon = new class // Comment
2222
$util->doSomething( new class {} );
2323
$b = new class extends SomeClass implements SomeInterface {};
2424

25+
/*
26+
* Safeguard handling of anon classes with attributes.
27+
*/
28+
$anon = new
29+
#[MyAttribute, AnotherAttribute]
30+
class() {}; // OK.
31+
32+
$anon = new
33+
#[AllowDynamicProperties]
34+
#[MyAttribute, AnotherAttribute]
35+
class {}; // Bad.
36+
2537
// Live coding.
2638
// Intentional parse error. This has to be the last test in the file.
2739
$anon = new class

Universal/Tests/Classes/RequireAnonClassParenthesesUnitTest.inc.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ $anon = new class // Comment
2222
$util->doSomething( new class() {} );
2323
$b = new class() extends SomeClass implements SomeInterface {};
2424

25+
/*
26+
* Safeguard handling of anon classes with attributes.
27+
*/
28+
$anon = new
29+
#[MyAttribute, AnotherAttribute]
30+
class() {}; // OK.
31+
32+
$anon = new
33+
#[AllowDynamicProperties]
34+
#[MyAttribute, AnotherAttribute]
35+
class() {}; // Bad.
36+
2537
// Live coding.
2638
// Intentional parse error. This has to be the last test in the file.
2739
$anon = new class

Universal/Tests/Classes/RequireAnonClassParenthesesUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function getErrorList()
3232
return [
3333
22 => 1,
3434
23 => 1,
35+
35 => 1,
3536
];
3637
}
3738

0 commit comments

Comments
 (0)