File tree 2 files changed +38
-0
lines changed
test/unit/Reflection/Adapter 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ class ReflectionClass extends CoreReflectionClass
33
33
public function __construct (BetterReflectionClass $ betterReflectionClass )
34
34
{
35
35
$ this ->betterReflectionClass = $ betterReflectionClass ;
36
+
37
+ unset($ this ->name );
36
38
}
37
39
38
40
/**
@@ -69,6 +71,22 @@ public function __toString()
69
71
return $ this ->betterReflectionClass ->__toString ();
70
72
}
71
73
74
+ /**
75
+ * @param string $name
76
+ *
77
+ * @return mixed
78
+ *
79
+ * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
80
+ */
81
+ public function __get ($ name )
82
+ {
83
+ if ($ name === 'name ' ) {
84
+ return $ this ->betterReflectionClass ->getName ();
85
+ }
86
+
87
+ throw new OutOfBoundsException (sprintf ('Property %s::$%s does not exist. ' , self ::class, $ name ));
88
+ }
89
+
72
90
/**
73
91
* {@inheritDoc}
74
92
*/
Original file line number Diff line number Diff line change @@ -512,4 +512,24 @@ public function testGetReflectionConstantReturnsFalseWhenConstantDoesNotExist():
512
512
513
513
self ::assertFalse ($ reflectionClassAdapter ->getReflectionConstant ('FOO ' ));
514
514
}
515
+
516
+ public function testPropertyName (): void
517
+ {
518
+ $ betterReflectionClass = $ this ->createMock (BetterReflectionClass::class);
519
+ $ betterReflectionClass
520
+ ->method ('getName ' )
521
+ ->willReturn ('Foo ' );
522
+
523
+ $ reflectionClassAdapter = new ReflectionClassAdapter ($ betterReflectionClass );
524
+ self ::assertSame ('Foo ' , $ reflectionClassAdapter ->name );
525
+ }
526
+
527
+ public function testUnknownProperty (): void
528
+ {
529
+ $ betterReflectionClass = $ this ->createMock (BetterReflectionClass::class);
530
+ $ reflectionClassAdapter = new ReflectionClassAdapter ($ betterReflectionClass );
531
+ $ this ->expectException (OutOfBoundsException::class);
532
+ $ this ->expectExceptionMessage ('Property Roave\BetterReflection\Reflection\Adapter\ReflectionClass::$foo does not exist. ' );
533
+ $ reflectionClassAdapter ->foo ;
534
+ }
515
535
}
You can’t perform that action at this time.
0 commit comments