Skip to content

Commit 447cd10

Browse files
kukulichondrejmirtes
authored andcommitted
Added tests that ClassAttributesRule supports enums as well
1 parent 29e8626 commit 447cd10

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,18 @@ public function testRule(): void
9797
]);
9898
}
9999

100+
public function testRuleForEnums(): void
101+
{
102+
if (!self::$useStaticReflectionProvider && PHP_VERSION_ID < 80100) {
103+
$this->markTestSkipped('Test requires PHP 8.1.');
104+
}
105+
106+
$this->analyse([__DIR__ . '/data/enum-attributes.php'], [
107+
[
108+
'Attribute class EnumAttributes\AttributeWithPropertyTarget does not have the class target.',
109+
23,
110+
],
111+
]);
112+
}
113+
100114
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php // lint >= 8.1
2+
3+
namespace EnumAttributes;
4+
5+
#[\Attribute]
6+
class AttributeWithoutSpecificTarget
7+
{
8+
9+
}
10+
11+
#[\Attribute(\Attribute::TARGET_PROPERTY)]
12+
class AttributeWithPropertyTarget
13+
{
14+
15+
}
16+
17+
#[AttributeWithoutSpecificTarget]
18+
enum EnumWithValidClassAttribute
19+
{
20+
21+
}
22+
23+
#[AttributeWithPropertyTarget]
24+
enum EnumWithInvalidClassAttribute
25+
{
26+
27+
}

0 commit comments

Comments
 (0)