From d4257ee557484ac886bee46bd41ebecb7c4bfa16 Mon Sep 17 00:00:00 2001 From: Lisachenko Alexander Date: Thu, 13 Aug 2020 03:18:30 +0300 Subject: [PATCH] Fix PHP7.4 deprecation errors, related to #102 --- tests/AbstractTestCase.php | 2 +- tests/ReflectionFunctionTest.php | 7 ++++++- tests/ReflectionParameterTest.php | 7 ++++++- tests/ReflectionTypeTest.php | 21 ++++++++++++++++++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 9150b60a..c146ad00 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -56,7 +56,7 @@ public function testCoverAllMethods() } if ($allMissedMethods) { - $this->markTestIncomplete('Methods ' . join($allMissedMethods, ', ') . ' are not implemented'); + $this->markTestIncomplete('Methods ' . join(', ', $allMissedMethods) . ' are not implemented'); } } diff --git a/tests/ReflectionFunctionTest.php b/tests/ReflectionFunctionTest.php index 2a07c2f6..fb18ae6d 100644 --- a/tests/ReflectionFunctionTest.php +++ b/tests/ReflectionFunctionTest.php @@ -125,7 +125,12 @@ public function testGetReturnTypeMethod() $originalReturnType = $originalRefFunction->getReturnType(); $this->assertSame($originalReturnType->allowsNull(), $parsedReturnType->allowsNull()); $this->assertSame($originalReturnType->isBuiltin(), $parsedReturnType->isBuiltin()); - $this->assertSame($originalReturnType->__toString(), $parsedReturnType->__toString()); + // TODO: To prevent deprecation error in tests + if (PHP_VERSION_ID < 70400) { + $this->assertSame($originalReturnType->__toString(), $parsedReturnType->__toString()); + } else { + $this->assertSame($originalReturnType->getName(), $parsedReturnType->__toString()); + } } else { $this->assertSame( $originalRefFunction->getReturnType(), diff --git a/tests/ReflectionParameterTest.php b/tests/ReflectionParameterTest.php index fe506b7f..d8e7b0f6 100644 --- a/tests/ReflectionParameterTest.php +++ b/tests/ReflectionParameterTest.php @@ -279,7 +279,12 @@ public function testGetTypeMethod() $originalReturnType = $originalRefParameter->getType(); $this->assertSame($originalReturnType->allowsNull(), $parsedReturnType->allowsNull(), $message); $this->assertSame($originalReturnType->isBuiltin(), $parsedReturnType->isBuiltin(), $message); - $this->assertSame($originalReturnType->__toString(), $parsedReturnType->__toString(), $message); + // TODO: To prevent deprecation error in tests + if (PHP_VERSION_ID < 70400) { + $this->assertSame($originalReturnType->__toString(), $parsedReturnType->__toString(), $message); + } else { + $this->assertSame($originalReturnType->getName(), $parsedReturnType->__toString(), $message); + } } else { $this->assertSame( $originalRefParameter->getType(), diff --git a/tests/ReflectionTypeTest.php b/tests/ReflectionTypeTest.php index 39dab937..25c108ea 100644 --- a/tests/ReflectionTypeTest.php +++ b/tests/ReflectionTypeTest.php @@ -28,7 +28,12 @@ public function testTypeConvertToDisplayTypeWithNativeType() $this->assertCount(2, $nativeParamRefArr); $this->assertEquals(\ReflectionParameter::class, get_class($nativeParamRefArr[0])); $nativeTypeRef = $nativeParamRefArr[0]->getType(); - $this->assertEquals('string', (string)$nativeTypeRef); + // TODO: To prevent deprecation error in tests + if (PHP_VERSION_ID < 70400) { + $this->assertEquals('string', (string)$nativeTypeRef); + } else { + $this->assertEquals('string', $nativeTypeRef->getName()); + } $this->assertNotContains('\\', get_class($nativeTypeRef)); $this->assertInstanceOf(\ReflectionType::class, $nativeTypeRef); $this->assertEquals('string', \Go\ParserReflection\ReflectionType::convertToDisplayType($nativeTypeRef)); @@ -49,7 +54,12 @@ public function testTypeConvertToDisplayTypeWithNullableNativeType() $this->assertCount(2, $nativeParamRefArr); $this->assertEquals(\ReflectionParameter::class, get_class($nativeParamRefArr[0])); $nativeTypeRef = $nativeParamRefArr[0]->getType(); - $this->assertEquals('string', (string)$nativeTypeRef); + // TODO: To prevent deprecation error in tests + if (PHP_VERSION_ID < 70400) { + $this->assertEquals('string', (string)$nativeTypeRef); + } else { + $this->assertEquals('string', $nativeTypeRef->getName()); + } $this->assertNotContains('\\', get_class($nativeTypeRef)); $this->assertInstanceOf(\ReflectionType::class, $nativeTypeRef); $this->assertEquals('string or NULL', \Go\ParserReflection\ReflectionType::convertToDisplayType($nativeTypeRef)); @@ -71,7 +81,12 @@ public function testTypeConvertToDisplayTypeImplicitlyNullable() $this->assertEquals(\ReflectionParameter::class, get_class($nativeParamRefArr[0])); $nativeTypeRef = $nativeParamRefArr[0]->getType(); $this->assertTrue($nativeTypeRef->allowsNull()); - $this->assertEquals('string', (string)$nativeTypeRef); + // TODO: To prevent deprecation error in tests + if (PHP_VERSION_ID < 70400) { + $this->assertEquals('string', (string)$nativeTypeRef); + } else { + $this->assertEquals('string', $nativeTypeRef->getName()); + } $this->assertNotContains('\\', get_class($nativeTypeRef)); $this->assertInstanceOf(\ReflectionType::class, $nativeTypeRef); $this->assertEquals('string or NULL', \Go\ParserReflection\ReflectionType::convertToDisplayType($nativeTypeRef));