22
33declare (strict_types=1 );
44
5- use MyCLabs \ Enum \ Enum ;
6- use PHPStan \Reflection \ ClassReflection ;
7- use PHPUnit \ Framework \ TestCase ;
5+ use PHPStan \ Reflection \ ParametersAcceptorSelector ;
6+ use PHPStan \Testing \ TestCase ;
7+ use PHPStan \ Type \ VerbosityLevel ;
88use Timeweb \PHPStan \Reflection \EnumMethodReflection ;
99use Timeweb \PHPStan \Reflection \EnumMethodsClassReflectionExtension ;
1010
1313 */
1414class EnumMethodsClassReflectionExtensionTest extends TestCase
1515{
16+ /**
17+ * @var \PHPStan\Broker\Broker
18+ */
19+ protected $ broker ;
20+
1621 /**
1722 * @var EnumMethodsClassReflectionExtension
1823 */
1924 protected $ reflectionExtension ;
2025
2126 public function setUp ()
2227 {
28+ $ this ->broker = $ this ->createBroker ();
2329 $ this ->reflectionExtension = new EnumMethodsClassReflectionExtension ();
2430 }
2531
@@ -29,19 +35,7 @@ public function setUp()
2935 */
3036 public function testEnumMethodsCanBeFoundInEnumSubclasses (bool $ expected , string $ methodName )
3137 {
32- $ classReflection = $ this ->createMock (ClassReflection::class);
33-
34- $ classReflection ->expects ($ this ->once ())
35- ->method ('getNativeReflection ' )
36- ->will ($ this ->returnValue (new ReflectionClass (EnumFixture::class)))
37- ;
38-
39- $ classReflection ->expects ($ this ->once ())
40- ->method ('isSubclassOf ' )
41- ->with ($ this ->equalTo (Enum::class))
42- ->will ($ this ->returnValue (true ))
43- ;
44-
38+ $ classReflection = $ this ->broker ->getClass (EnumFixture::class);
4539 $ hasMethod = $ this ->reflectionExtension ->hasMethod ($ classReflection , $ methodName );
4640
4741 $ this ->assertEquals ($ expected , $ hasMethod );
@@ -60,14 +54,7 @@ public function methodNameDataProvider(): array
6054 */
6155 public function testEnumMethodsCannotBeFoundInNonEnumSubclasses ()
6256 {
63- $ classReflection = $ this ->createMock (ClassReflection::class);
64-
65- $ classReflection ->expects ($ this ->once ())
66- ->method ('isSubclassOf ' )
67- ->with ($ this ->equalTo (Enum::class))
68- ->will ($ this ->returnValue (false ))
69- ;
70-
57+ $ classReflection = $ this ->broker ->getClass (EnumFixture::class);
7158 $ hasMethod = $ this ->reflectionExtension ->hasMethod ($ classReflection , 'SOME_NAME ' );
7259
7360 $ this ->assertFalse ($ hasMethod );
@@ -79,10 +66,43 @@ public function testEnumMethodsCannotBeFoundInNonEnumSubclasses()
7966 */
8067 public function testEnumMethodReflectionCanBeObtained ()
8168 {
82- $ classReflection = $ this ->createMock (ClassReflection::class);
83-
69+ $ classReflection = $ this ->broker ->getClass (EnumFixture::class);
8470 $ methodReflection = $ this ->reflectionExtension ->getMethod ($ classReflection , 'SOME_NAME ' );
8571
8672 $ this ->assertInstanceOf (EnumMethodReflection::class, $ methodReflection );
8773 }
74+
75+ /**
76+ * @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::getName
77+ * @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::getDeclaringClass
78+ * @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::isStatic
79+ * @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::isPrivate
80+ * @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::isPublic
81+ * @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::getPrototype
82+ * @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::getVariants
83+ * @uses Timeweb\PHPStan\Reflection\EnumMethodReflection
84+ * @dataProvider enumFixtureProperties
85+ */
86+ public function testEnumMethodProperties (string $ propertyName )
87+ {
88+ $ classReflection = $ this ->broker ->getClass (EnumFixture::class);
89+ $ methodReflection = $ this ->reflectionExtension ->getMethod ($ classReflection , $ propertyName );
90+ $ parametersAcceptor = ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ());
91+
92+ $ this ->assertSame ($ propertyName , $ methodReflection ->getName ());
93+ $ this ->assertSame ($ classReflection , $ methodReflection ->getDeclaringClass ());
94+ $ this ->assertTrue ($ methodReflection ->isStatic ());
95+ $ this ->assertFalse ($ methodReflection ->isPrivate ());
96+ $ this ->assertTrue ($ methodReflection ->isPublic ());
97+ $ this ->assertSame (EnumFixture::class, $ parametersAcceptor ->getReturnType ()->describe (VerbosityLevel::value ()));
98+ }
99+
100+ public function enumFixtureProperties (): array
101+ {
102+ return [
103+ ['MEMBER ' ],
104+ ['PUBLIC_CONST ' ],
105+ ['PRIVATE_CONST ' ],
106+ ];
107+ }
88108}
0 commit comments