Skip to content

Commit b46486e

Browse files
committed
Add test cases for attributes and doc comments on trait constants
1 parent b4f7f24 commit b46486e

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Zend/tests/traits/constant_020.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Attributes can be retrieved from trait constants
3+
--FILE--
4+
<?php
5+
6+
class TestAttribute {
7+
public function __construct(public string $value) {}
8+
}
9+
10+
trait TestTrait {
11+
#[TestAttribute(value: 123)]
12+
public const Constant = 42;
13+
}
14+
15+
class TestClass {
16+
use TestTrait;
17+
}
18+
19+
$reflection = new \ReflectionClass(TestTrait::class);
20+
var_dump($reflection->getReflectionConstant('Constant')->getAttributes('TestAttribute')[0]->getArguments()['value']);
21+
22+
$reflection = new \ReflectionClass(TestClass::class);
23+
var_dump($reflection->getReflectionConstant('Constant')->getAttributes('TestAttribute')[0]->getArguments()['value']);
24+
25+
?>
26+
--EXPECTF--
27+
int(123)
28+
int(123)

Zend/tests/traits/constant_021.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Doc comments can be retrieved from trait constants
3+
--FILE--
4+
<?php
5+
6+
trait TestTrait {
7+
/** DocComments */
8+
public const Constant = 42;
9+
}
10+
11+
class TestClass {
12+
use TestTrait;
13+
}
14+
15+
$reflection = new \ReflectionClass(TestTrait::class);
16+
var_dump($reflection->getReflectionConstant('Constant')->getDocComment());
17+
18+
$reflection = new \ReflectionClass(TestClass::class);
19+
var_dump($reflection->getReflectionConstant('Constant')->getDocComment());
20+
21+
?>
22+
--EXPECTF--
23+
string(18) "/** DocComments */"
24+
string(18) "/** DocComments */"

0 commit comments

Comments
 (0)