Repository: Roave/BetterReflection (php)

Issue:
Adapter ReflectionClass::getReflectionConstant returns null but should return false
See PoC fix: https://github.com/ondrejmirtes/BetterReflection/commit/07af30d92461a6a4e34194d21ab188b32e9cfcaa

Pull request description:
Fixed ReflectionClass::getReflectionConstant() in adapter for non-existent constant
Fixes #625 

Patch:
diff --git a/src/Reflection/Adapter/ReflectionClass.php b/src/Reflection/Adapter/ReflectionClass.php
index 619ec433..87fb71f5 100644
--- a/src/Reflection/Adapter/ReflectionClass.php
+++ b/src/Reflection/Adapter/ReflectionClass.php
@@ -249,9 +249,12 @@ class ReflectionClass extends CoreReflectionClass
      */
     public function getReflectionConstant($name)
     {
-        return new ReflectionClassConstant(
-            $this->betterReflectionClass->getReflectionConstant($name),
-        );
+        $betterReflectionConstant = $this->betterReflectionClass->getReflectionConstant($name);
+        if ($betterReflectionConstant === null) {
+            return false;
+        }
+
+        return new ReflectionClassConstant($betterReflectionConstant);
     }
 
     /**


Test patch:
diff --git a/test/unit/Reflection/Adapter/ReflectionClassTest.php b/test/unit/Reflection/Adapter/ReflectionClassTest.php
index 6966eaba..59be357f 100644
--- a/test/unit/Reflection/Adapter/ReflectionClassTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionClassTest.php
@@ -498,4 +498,17 @@ class ReflectionClassTest extends TestCase
 
         self::assertNull($reflectionClassAdapter->isInstance('string'));
     }
+
+    public function testGetReflectionConstantReturnsFalseWhenConstantDoesNotExist() : void
+    {
+        $betterReflectionClass = $this->createMock(BetterReflectionClass::class);
+        $betterReflectionClass
+            ->method('getReflectionConstant')
+            ->with('FOO')
+            ->willReturn(null);
+
+        $reflectionClassAdapter = new ReflectionClassAdapter($betterReflectionClass);
+
+        self::assertFalse($reflectionClassAdapter->getReflectionConstant('FOO'));
+    }
 }