12
12
namespace HyperfTest \Di ;
13
13
14
14
use Hyperf \Di \LazyLoader \PublicMethodVisitor ;
15
+ use Hyperf \Utils \CodeGen \PhpParser ;
15
16
use PhpParser \NodeTraverser ;
16
17
use PhpParser \ParserFactory ;
17
18
use PhpParser \PrettyPrinter \Standard ;
18
19
use PHPUnit \Framework \TestCase ;
19
- use Roave \BetterReflection \BetterReflection ;
20
- use Roave \BetterReflection \Reflection \Adapter \ReflectionMethod ;
21
- use Roave \BetterReflection \Reflector \ClassReflector ;
22
- use Roave \BetterReflection \SourceLocator \Type \StringSourceLocator ;
23
20
24
21
/**
25
22
* @internal
@@ -48,7 +45,7 @@ public function hope(bool $a) : int
48
45
{
49
46
return $this->__call(__FUNCTION__, func_get_args());
50
47
}
51
- public function it(\bar\ ConfigInterface $a) : void
48
+ public function it(ConfigInterface $a) : void
52
49
{
53
50
$this->__call(__FUNCTION__, func_get_args());
54
51
}
@@ -64,7 +61,7 @@ public function fluent() : \foo\foo
64
61
$ parser = (new ParserFactory ())->create (ParserFactory::PREFER_PHP7 );
65
62
$ ast = $ parser ->parse ($ code );
66
63
$ traverser = new NodeTraverser ();
67
- $ visitor = new PublicMethodVisitor (...$ this ->getStmt ($ code ));
64
+ $ visitor = new PublicMethodVisitor (...$ this ->getStmt ($ ast ));
68
65
$ traverser ->addVisitor ($ visitor );
69
66
$ ast = $ traverser ->traverse ($ ast );
70
67
$ prettyPrinter = new Standard ();
@@ -103,7 +100,7 @@ public function hope(bool $a) : int
103
100
{
104
101
return $this->__call(__FUNCTION__, func_get_args());
105
102
}
106
- public function it(\bar\ ConfigInterface $a) : void
103
+ public function it(ConfigInterface $a) : void
107
104
{
108
105
$this->__call(__FUNCTION__, func_get_args());
109
106
}
@@ -119,7 +116,7 @@ public function fluent() : \foo\foo
119
116
$ parser = (new ParserFactory ())->create (ParserFactory::PREFER_PHP7 );
120
117
$ ast = $ parser ->parse ($ code );
121
118
$ traverser = new NodeTraverser ();
122
- $ visitor = new PublicMethodVisitor (...$ this ->getStmt ($ code ));
119
+ $ visitor = new PublicMethodVisitor (...$ this ->getStmt ($ ast ));
123
120
$ traverser ->addVisitor ($ visitor );
124
121
$ ast = $ traverser ->traverse ($ ast );
125
122
$ prettyPrinter = new Standard ();
@@ -128,16 +125,9 @@ public function fluent() : \foo\foo
128
125
$ this ->assertEquals (4 , count ($ visitor ->nodes ));
129
126
}
130
127
131
- private function getStmt ($ code )
128
+ private function getStmt ($ ast )
132
129
{
133
- $ astLocator = (new BetterReflection ())->astLocator ();
134
- $ reflector = new ClassReflector (new StringSourceLocator ($ code , $ astLocator ));
135
- $ reflectionClass = $ reflector ->reflect ('foo \\foo ' );
136
- $ reflectionMethods = $ reflectionClass ->getMethods (ReflectionMethod::IS_PUBLIC );
137
- $ stmts = [];
138
- foreach ($ reflectionMethods as $ method ) {
139
- $ stmts [] = $ method ->getAst ();
140
- }
130
+ $ stmts = PhpParser::getInstance ()->getAllMethodsFromStmts ($ ast );
141
131
return [$ stmts , 'foo \\foo ' ];
142
132
}
143
133
}
0 commit comments