File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
test/unit/Reflection/Adapter Expand file tree Collapse file tree 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
3333 public function __construct (BetterReflectionClass $ betterReflectionClass )
3434 {
3535 $ this ->betterReflectionClass = $ betterReflectionClass ;
36+
37+ unset($ this ->name );
3638 }
3739
3840 /**
@@ -69,6 +71,22 @@ public function __toString()
6971 return $ this ->betterReflectionClass ->__toString ();
7072 }
7173
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+
7290 /**
7391 * {@inheritDoc}
7492 */
Original file line number Diff line number Diff line change @@ -512,4 +512,24 @@ public function testGetReflectionConstantReturnsFalseWhenConstantDoesNotExist():
512512
513513 self ::assertFalse ($ reflectionClassAdapter ->getReflectionConstant ('FOO ' ));
514514 }
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+ }
515535}
You can’t perform that action at this time.
0 commit comments