Skip to content

Commit 5637f30

Browse files
Test repeating attributes
1 parent 00f6020 commit 5637f30

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Validation of attribute repetition (not allowed; internal attribute)
3+
--FILE--
4+
<?php
5+
6+
#[Deprecated]
7+
#[Deprecated]
8+
const MY_CONST = true;
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Attribute "Deprecated" must not be repeated in %s on line %d
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Validation of attribute repetition (not allowed; userland attribute)
3+
--FILE--
4+
<?php
5+
6+
#[Attribute]
7+
class MyAttribute {}
8+
9+
#[MyAttribute]
10+
#[MyAttribute]
11+
const MY_CONST = true;
12+
13+
$attributes = new ReflectionConstant( 'MY_CONST' )->getAttributes();
14+
var_dump( $attributes );
15+
$attributes[0]->newInstance();
16+
17+
?>
18+
--EXPECTF--
19+
array(2) {
20+
[0]=>
21+
object(ReflectionAttribute)#%d (1) {
22+
["name"]=>
23+
string(11) "MyAttribute"
24+
}
25+
[1]=>
26+
object(ReflectionAttribute)#%d (1) {
27+
["name"]=>
28+
string(11) "MyAttribute"
29+
}
30+
}
31+
32+
Fatal error: Uncaught Error: Attribute "MyAttribute" must not be repeated in %s:%d
33+
Stack trace:
34+
#0 %s(%d): ReflectionAttribute->newInstance()
35+
#1 {main}
36+
thrown in %s on line %d
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Validation of attribute repetition (is allowed; internal attribute)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
#[ZendTestRepeatableAttribute]
9+
#[ZendTestRepeatableAttribute]
10+
const MY_CONST = true;
11+
12+
echo "Done\n";
13+
14+
?>
15+
--EXPECT--
16+
Done
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Validation of attribute repetition (is allowed; userland attribute)
3+
--FILE--
4+
<?php
5+
6+
#[Attribute(Attribute::TARGET_ALL|Attribute::IS_REPEATABLE)]
7+
class MyAttribute {}
8+
9+
#[MyAttribute]
10+
#[MyAttribute]
11+
const MY_CONST = true;
12+
13+
$attributes = new ReflectionConstant( 'MY_CONST' )->getAttributes();
14+
var_dump( $attributes );
15+
$attributes[0]->newInstance();
16+
17+
?>
18+
--EXPECTF--
19+
array(2) {
20+
[0]=>
21+
object(ReflectionAttribute)#%d (1) {
22+
["name"]=>
23+
string(11) "MyAttribute"
24+
}
25+
[1]=>
26+
object(ReflectionAttribute)#%d (1) {
27+
["name"]=>
28+
string(11) "MyAttribute"
29+
}
30+
}

0 commit comments

Comments
 (0)