22
33namespace Tests \PHPStan \Reflection \Doctrine ;
44
5- use PHPStan \Broker \Broker ;
6- use PHPStan \Reflection \ClassReflection ;
75use PHPStan \Reflection \Doctrine \DoctrineSelectableClassReflectionExtension ;
8- use PHPStan \Reflection \MethodReflection ;
9- use PHPStan \Reflection \Php \PhpMethodReflection ;
10- use PHPUnit \Framework \TestCase ;
116
12- final class DoctrineSelectableClassReflectionExtensionTest extends TestCase
7+ final class DoctrineSelectableClassReflectionExtensionTest extends \ PHPStan \ Testing \ TestCase
138{
149
10+ /** @var \PHPStan\Broker\Broker */
11+ private $ broker ;
12+
1513 /** @var \PHPStan\Reflection\Doctrine\DoctrineSelectableClassReflectionExtension */
1614 private $ extension ;
1715
1816 protected function setUp ()
1917 {
20- $ broker = $ this ->mockBroker ();
18+ $ this -> broker = $ this ->createBroker ();
2119
2220 $ this ->extension = new DoctrineSelectableClassReflectionExtension ();
23- $ this ->extension ->setBroker ($ broker );
21+ $ this ->extension ->setBroker ($ this -> broker );
2422 }
2523
2624 /**
@@ -42,48 +40,15 @@ public function dataHasMethod(): array
4240 */
4341 public function testHasMethod (string $ className , string $ method , bool $ expectedResult )
4442 {
45- $ classReflection = $ this ->mockClassReflection ( new \ ReflectionClass ( $ className) );
43+ $ classReflection = $ this ->broker -> getClass ( $ className );
4644 $ this ->assertSame ($ expectedResult , $ this ->extension ->hasMethod ($ classReflection , $ method ));
4745 }
4846
4947 public function testGetMethod ()
5048 {
51- $ classReflection = $ this ->mockClassReflection ( new \ ReflectionClass (\ Doctrine \Common \Collections \Collection::class) );
49+ $ classReflection = $ this ->broker -> getClass (\ Doctrine \Common \Collections \Collection::class);
5250 $ methodReflection = $ this ->extension ->getMethod ($ classReflection , 'matching ' );
5351 $ this ->assertSame ('matching ' , $ methodReflection ->getName ());
5452 }
5553
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-
8954}
0 commit comments