Skip to content

Commit ff9cafe

Browse files
More tests
1 parent 4038389 commit ff9cafe

3 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
ReflectionAttribute::getCurrent() when called from another method invoked by constructor
3+
--FILE--
4+
<?php
5+
6+
#[Attribute]
7+
class Demo {
8+
public function __construct( $args ) {
9+
echo ReflectionAttribute::getCurrent();
10+
$this->test();
11+
}
12+
13+
private function test() {
14+
echo ReflectionAttribute::getCurrent();
15+
}
16+
}
17+
18+
#[Demo("global constant")]
19+
const GLOBAL_CONSTANT = true;
20+
21+
$case = new ReflectionConstant( 'GLOBAL_CONSTANT' );
22+
echo $case;
23+
echo "\n";
24+
$case->getAttributes()[0]->newInstance();
25+
26+
?>
27+
--EXPECTF--
28+
Constant [ bool GLOBAL_CONSTANT ] { 1 }
29+
30+
Constant [ bool GLOBAL_CONSTANT ] { 1 }
31+
32+
Fatal error: Uncaught Error: Current function was not invoked via ReflectionAttribute::newInstance() in %s:%d
33+
Stack trace:
34+
#0 %s(%d): ReflectionAttribute::getCurrent()
35+
#1 %s(%d): Demo->test()
36+
#2 %s(%d): Demo->__construct('global constant')
37+
#3 %s(%d): ReflectionAttribute->newInstance()
38+
#4 {main}
39+
thrown in %s on line %d
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
ReflectionAttribute::getCurrent() when in the global scope
3+
--FILE--
4+
<?php
5+
6+
echo ReflectionAttribute::getCurrent();
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Uncaught Error: Current function was not invoked via ReflectionAttribute::newInstance() in %s:%d
11+
Stack trace:
12+
#0 %s(%d): ReflectionAttribute::getCurrent()
13+
#1 {main}
14+
thrown in %s on line %d
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
ReflectionAttribute::getCurrent() when attribute constructed manually
3+
--FILE--
4+
<?php
5+
6+
#[Attribute]
7+
class Demo {
8+
public function __construct( $args ) {
9+
echo ReflectionAttribute::getCurrent();
10+
}
11+
}
12+
13+
#[Demo("global constant")]
14+
const GLOBAL_CONSTANT = true;
15+
16+
$case = new ReflectionConstant( 'GLOBAL_CONSTANT' );
17+
echo $case;
18+
echo "\n";
19+
$case->getAttributes()[0]->newInstance();
20+
21+
new Demo(null);
22+
23+
?>
24+
--EXPECTF--
25+
Constant [ bool GLOBAL_CONSTANT ] { 1 }
26+
27+
Constant [ bool GLOBAL_CONSTANT ] { 1 }
28+
29+
Fatal error: Uncaught Error: Current function was not invoked via ReflectionAttribute::newInstance() in %s:%d
30+
Stack trace:
31+
#0 %s(%d): ReflectionAttribute::getCurrent()
32+
#1 %s(%d): Demo->__construct(NULL)
33+
#2 {main}
34+
thrown in %s on line %d

0 commit comments

Comments
 (0)