2
2
3
3
namespace Tests \PHPStan \Reflection \Doctrine ;
4
4
5
- use PHPStan \Broker \Broker ;
6
- use PHPStan \Reflection \ClassReflection ;
7
5
use PHPStan \Reflection \Doctrine \DoctrineSelectableClassReflectionExtension ;
8
- use PHPStan \Reflection \MethodReflection ;
9
- use PHPStan \Reflection \Php \PhpMethodReflection ;
10
- use PHPUnit \Framework \TestCase ;
11
6
12
- final class DoctrineSelectableClassReflectionExtensionTest extends TestCase
7
+ final class DoctrineSelectableClassReflectionExtensionTest extends \ PHPStan \ Testing \ TestCase
13
8
{
14
9
10
+ /** @var \PHPStan\Broker\Broker */
11
+ private $ broker ;
12
+
15
13
/** @var \PHPStan\Reflection\Doctrine\DoctrineSelectableClassReflectionExtension */
16
14
private $ extension ;
17
15
18
16
protected function setUp ()
19
17
{
20
- $ broker = $ this ->mockBroker ();
18
+ $ this -> broker = $ this ->createBroker ();
21
19
22
20
$ this ->extension = new DoctrineSelectableClassReflectionExtension ();
23
- $ this ->extension ->setBroker ($ broker );
21
+ $ this ->extension ->setBroker ($ this -> broker );
24
22
}
25
23
26
24
/**
@@ -42,48 +40,15 @@ public function dataHasMethod(): array
42
40
*/
43
41
public function testHasMethod (string $ className , string $ method , bool $ expectedResult )
44
42
{
45
- $ classReflection = $ this ->mockClassReflection ( new \ ReflectionClass ( $ className) );
43
+ $ classReflection = $ this ->broker -> getClass ( $ className );
46
44
$ this ->assertSame ($ expectedResult , $ this ->extension ->hasMethod ($ classReflection , $ method ));
47
45
}
48
46
49
47
public function testGetMethod ()
50
48
{
51
- $ classReflection = $ this ->mockClassReflection ( new \ ReflectionClass (\ Doctrine \Common \Collections \Collection::class) );
49
+ $ classReflection = $ this ->broker -> getClass (\ Doctrine \Common \Collections \Collection::class);
52
50
$ methodReflection = $ this ->extension ->getMethod ($ classReflection , 'matching ' );
53
51
$ this ->assertSame ('matching ' , $ methodReflection ->getName ());
54
52
}
55
53
56
- private function mockBroker (): Broker
57
- {
58
- $ broker = $ this ->createMock (Broker::class);
59
-
60
- $ broker ->method ('getClass ' )->willReturnCallback (
61
- function (string $ className ): ClassReflection {
62
- return $ this ->mockClassReflection (new \ReflectionClass ($ className ));
63
- }
64
- );
65
-
66
- return $ broker ;
67
- }
68
-
69
- private function mockClassReflection (\ReflectionClass $ reflectionClass ): ClassReflection
70
- {
71
- $ classReflection = $ this ->createMock (ClassReflection::class);
72
- $ classReflection ->method ('getName ' )->willReturn ($ reflectionClass ->getName ());
73
- $ classReflection ->method ('getNativeMethod ' )->willReturnCallback (
74
- function (string $ method ) use ($ reflectionClass ): MethodReflection {
75
- return $ this ->mockMethodReflection ($ reflectionClass ->getMethod ($ method ));
76
- }
77
- );
78
-
79
- return $ classReflection ;
80
- }
81
-
82
- private function mockMethodReflection (\ReflectionMethod $ method ): PhpMethodReflection
83
- {
84
- $ methodReflection = $ this ->createMock (PhpMethodReflection::class);
85
- $ methodReflection ->method ('getName ' )->willReturn ($ method ->getName ());
86
- return $ methodReflection ;
87
- }
88
-
89
54
}
0 commit comments