Skip to content

Commit

Permalink
Merge 77bce51 into 1966e14
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 9, 2024
2 parents 1966e14 + 77bce51 commit 289f084
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
- "lowest"
- "highest"
php-version:
- "7.4"
- "8.0"
operating-system:
- "ubuntu-latest"

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -22,11 +22,11 @@
}
},
"require": {
"php": ">=7.4",
"php": ">=8.0",
"nikic/php-parser": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^9.0"
},
"extra": {
"branch-alias": {
Expand Down
28 changes: 11 additions & 17 deletions phpunit.xml.dist
@@ -1,19 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
bootstrap="./vendor/autoload.php"
>
<testsuites>
<testsuite name="Parser Reflection Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" bootstrap="./vendor/autoload.php">
<coverage>
<include>
<directory>./src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Parser Reflection Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/ReflectionClassConstant.php
Expand Up @@ -200,7 +200,7 @@ public function __toString()
];
$value = $this->getValue();
$type = gettype($value);
if (PHP_VERSION_ID >= 70300 && isset($typeMap[$type])) {
if (isset($typeMap[$type])) {
$type = $typeMap[$type];
}
$valueType = new ReflectionType($type, null, true);
Expand Down
4 changes: 2 additions & 2 deletions src/ReflectionFunction.php
Expand Up @@ -77,11 +77,11 @@ public function getClosure()
/**
* {@inheritDoc}
*/
public function invoke($args = null)
public function invoke(mixed ...$args)
{
$this->initializeInternalReflection();

return parent::invoke(...func_get_args());
return parent::invoke(...$args);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/ReflectionMethod.php
Expand Up @@ -203,17 +203,17 @@ public function getPrototype()
/**
* {@inheritDoc}
*/
public function invoke($object, $args = null)
public function invoke(?object $object, mixed ...$args): mixed
{
$this->initializeInternalReflection();

return parent::invoke(...func_get_args());
return parent::invoke($object, ...$args);
}

/**
* {@inheritDoc}
*/
public function invokeArgs($object, array $args)
public function invokeArgs(?object $object, array $args): mixed
{
$this->initializeInternalReflection();

Expand Down
12 changes: 4 additions & 8 deletions src/Traits/ReflectionClassLikeTrait.php
Expand Up @@ -221,7 +221,7 @@ public function getConstant($name)
/**
* {@inheritDoc}
*/
public function getConstants()
public function getConstants(?int $filter = null): array
{
if (!isset($this->constants)) {
$this->constants = $this->recursiveCollect(
Expand Down Expand Up @@ -417,10 +417,6 @@ public function getModifiers()
$modifiers += \ReflectionClass::IS_FINAL;
}

if (PHP_VERSION_ID < 70000 && $this->isTrait()) {
$modifiers += \ReflectionClass::IS_EXPLICIT_ABSTRACT;
}

if ($this->classLikeNode instanceof Class_ && $this->classLikeNode->isAbstract()) {
$modifiers += \ReflectionClass::IS_EXPLICIT_ABSTRACT;
}
Expand Down Expand Up @@ -553,7 +549,7 @@ public function getReflectionConstant($name)
/**
* @inheritDoc
*/
public function getReflectionConstants()
public function getReflectionConstants(?int $filter = null): array
{
if (!isset($this->classConstants)) {
$directClassConstants = ReflectionClassConstant::collectFromClassNode(
Expand Down Expand Up @@ -965,12 +961,12 @@ public function newInstanceArgs(array $args = [])
*
* @return object
*/
public function newInstanceWithoutConstructor($args = null)
public function newInstanceWithoutConstructor()
{
$function = __FUNCTION__;
$this->initializeInternalReflection();

return parent::$function($args);
return parent::$function();
}

/**
Expand Down
13 changes: 3 additions & 10 deletions tests/AbstractTestCase.php
Expand Up @@ -71,16 +71,9 @@ public function testCoverAllMethods()
public function getFilesToAnalyze()
{
$files = ['PHP5.5' => [__DIR__ . '/Stub/FileWithClasses55.php']];

if (PHP_VERSION_ID >= 50600) {
$files['PHP5.6'] = [__DIR__ . '/Stub/FileWithClasses56.php'];
}
if (PHP_VERSION_ID >= 70000) {
$files['PHP7.0'] = [__DIR__ . '/Stub/FileWithClasses70.php'];
}
if (PHP_VERSION_ID >= 70100) {
$files['PHP7.1'] = [__DIR__ . '/Stub/FileWithClasses71.php'];
}
$files['PHP5.6'] = [__DIR__ . '/Stub/FileWithClasses56.php'];
$files['PHP7.0'] = [__DIR__ . '/Stub/FileWithClasses70.php'];
$files['PHP7.1'] = [__DIR__ . '/Stub/FileWithClasses71.php'];

return $files;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ReflectionClassTest.php
Expand Up @@ -30,7 +30,7 @@ class ReflectionClassTest extends AbstractTestCase
*/
public function testGetModifiers($fileName)
{
if (PHP_VERSION_ID >= 70400) {
if (PHP_VERSION_ID >= 80000) {
$this->markTestSkipped('TODO: Fix mapping and logic of modifiers');
}
$mask =
Expand Down
17 changes: 3 additions & 14 deletions tests/ReflectionFunctionTest.php
Expand Up @@ -34,9 +34,7 @@ public function testGeneralInfoGetters()
'returnsReference', 'getClosureScopeClass', 'getClosureThis'
];

if (PHP_VERSION_ID >= 70000) {
$allNameGetters[] = 'hasReturnType';
}
$allNameGetters[] = 'hasReturnType';

foreach ($this->parsedRefFile->getFileNamespaces() as $fileNamespace) {
foreach ($fileNamespace->getFunctions() as $refFunction) {
Expand Down Expand Up @@ -72,7 +70,7 @@ public function testCoverAllMethods()
}

if ($allMissedMethods) {
$this->markTestIncomplete('Methods ' . join($allMissedMethods, ', ') . ' are not implemented');
$this->markTestIncomplete('Methods ' . implode(', ', $allMissedMethods) . ' are not implemented');
}
}

Expand Down Expand Up @@ -105,10 +103,6 @@ public function testInvokeArgsMethod()

public function testGetReturnTypeMethod()
{
if (PHP_VERSION_ID < 70000) {
$this->markTestSkipped('Test available only for PHP7.0 and newer');
}

$fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE70);

$reflectionFile = new ReflectionFile($fileName);
Expand All @@ -129,12 +123,7 @@ public function testGetReturnTypeMethod()
$originalReturnType = $originalRefFunction->getReturnType();
$this->assertSame($originalReturnType->allowsNull(), $parsedReturnType->allowsNull());
$this->assertSame($originalReturnType->isBuiltin(), $parsedReturnType->isBuiltin());
// 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());
}
$this->assertSame($originalReturnType->getName(), $parsedReturnType->__toString());
} else {
$this->assertSame(
$originalRefFunction->getReturnType(),
Expand Down
11 changes: 3 additions & 8 deletions tests/ReflectionMethodTest.php
Expand Up @@ -146,14 +146,9 @@ protected function getGettersToCheck()
'getNumberOfRequiredParameters', 'returnsReference', 'getClosureScopeClass', 'getClosureThis'
];

if (PHP_VERSION_ID >= 50600) {
$allNameGetters[] = 'isVariadic';
$allNameGetters[] = 'isGenerator';
}

if (PHP_VERSION_ID >= 70000) {
$allNameGetters[] = 'hasReturnType';
}
$allNameGetters[] = 'isVariadic';
$allNameGetters[] = 'isGenerator';
$allNameGetters[] = 'hasReturnType';

return $allNameGetters;
}
Expand Down
29 changes: 6 additions & 23 deletions tests/ReflectionParameterTest.php
Expand Up @@ -34,12 +34,8 @@ public function testGeneralInfoGetters($fileName)
$onlyWithDefaultValues = array_flip([
'getDefaultValue', 'getDefaultValueConstantName', 'isDefaultValueConstant'
]);
if (PHP_VERSION_ID >= 50600) {
$allNameGetters[] = 'isVariadic';
}
if (PHP_VERSION_ID >= 70000) {
$allNameGetters[] = 'hasType';
}
$allNameGetters[] = 'isVariadic';
$allNameGetters[] = 'hasType';

foreach ($this->parsedRefFile->getFileNamespaces() as $fileNamespace) {
foreach ($fileNamespace->getFunctions() as $refFunction) {
Expand Down Expand Up @@ -75,13 +71,8 @@ public function testGeneralInfoGetters($fileName)
public function fileProvider()
{
$files = ['PHP5.5' => [__DIR__ . '/Stub/FileWithParameters55.php']];

if (PHP_VERSION_ID >= 50600) {
$files['PHP5.6'] = [__DIR__ . '/Stub/FileWithParameters56.php'];
}
if (PHP_VERSION_ID >= 70000) {
$files['PHP7.0'] = [__DIR__ . '/Stub/FileWithParameters70.php'];
}
$files['PHP5.6'] = [__DIR__ . '/Stub/FileWithParameters56.php'];
$files['PHP7.0'] = [__DIR__ . '/Stub/FileWithParameters70.php'];

return $files;
}
Expand Down Expand Up @@ -253,15 +244,12 @@ public function testCoverAllMethods()
}

if ($allMissedMethods) {
$this->markTestIncomplete('Methods ' . join($allMissedMethods, ', ') . ' are not implemented');
$this->markTestIncomplete('Methods ' . implode(', ', $allMissedMethods) . ' are not implemented');
}
}

public function testGetTypeMethod()
{
if (PHP_VERSION_ID < 70000) {
$this->markTestSkipped('Test available only for PHP7.0 and newer');
}
$this->setUpFile(__DIR__ . '/Stub/FileWithParameters70.php');

foreach ($this->parsedRefFile->getFileNamespaces() as $fileNamespace) {
Expand All @@ -282,12 +270,7 @@ public function testGetTypeMethod()
$originalReturnType = $originalRefParameter->getType();
$this->assertSame($originalReturnType->allowsNull(), $parsedReturnType->allowsNull(), $message);
$this->assertSame($originalReturnType->isBuiltin(), $parsedReturnType->isBuiltin(), $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);
}
$this->assertSame($originalReturnType->getName(), $parsedReturnType->__toString(), $message);
} else {
$this->assertSame(
$originalRefParameter->getType(),
Expand Down
29 changes: 5 additions & 24 deletions tests/ReflectionTypeTest.php
Expand Up @@ -9,12 +9,8 @@ class ReflectionTypeTest extends TestCase
{
protected function setUp(): void
{
if (PHP_VERSION_ID >= 70000) {
include_once (__DIR__ . '/Stub/FileWithClasses70.php');
}
if (PHP_VERSION_ID >= 70100) {
include_once (__DIR__ . '/Stub/FileWithClasses71.php');
}
include_once (__DIR__ . '/Stub/FileWithClasses70.php');
include_once (__DIR__ . '/Stub/FileWithClasses71.php');
}

/**
Expand All @@ -32,12 +28,7 @@ public function testTypeConvertToDisplayTypeWithNativeType()
$this->assertCount(2, $nativeParamRefArr);
$this->assertEquals(\ReflectionParameter::class, get_class($nativeParamRefArr[0]));
$nativeTypeRef = $nativeParamRefArr[0]->getType();
// TODO: To prevent deprecation error in tests
if (PHP_VERSION_ID < 70400) {
$this->assertEquals('string', (string)$nativeTypeRef);
} else {
$this->assertEquals('string', $nativeTypeRef->getName());
}
$this->assertEquals('string', $nativeTypeRef->getName());
$this->assertStringNotContainsString('\\', get_class($nativeTypeRef));
$this->assertInstanceOf(\ReflectionType::class, $nativeTypeRef);
$this->assertEquals('string', \Go\ParserReflection\ReflectionType::convertToDisplayType($nativeTypeRef));
Expand All @@ -58,12 +49,7 @@ public function testTypeConvertToDisplayTypeWithNullableNativeType()
$this->assertCount(2, $nativeParamRefArr);
$this->assertEquals(\ReflectionParameter::class, get_class($nativeParamRefArr[0]));
$nativeTypeRef = $nativeParamRefArr[0]->getType();
// TODO: To prevent deprecation error in tests
if (PHP_VERSION_ID < 70400) {
$this->assertEquals('string', (string)$nativeTypeRef);
} else {
$this->assertEquals('string', $nativeTypeRef->getName());
}
$this->assertEquals('string', $nativeTypeRef->getName());
$this->assertStringNotContainsString('\\', get_class($nativeTypeRef));
$this->assertInstanceOf(\ReflectionType::class, $nativeTypeRef);
$this->assertEquals('string or NULL', \Go\ParserReflection\ReflectionType::convertToDisplayType($nativeTypeRef));
Expand All @@ -85,12 +71,7 @@ public function testTypeConvertToDisplayTypeImplicitlyNullable()
$this->assertEquals(\ReflectionParameter::class, get_class($nativeParamRefArr[0]));
$nativeTypeRef = $nativeParamRefArr[0]->getType();
$this->assertTrue($nativeTypeRef->allowsNull());
// TODO: To prevent deprecation error in tests
if (PHP_VERSION_ID < 70400) {
$this->assertEquals('string', (string)$nativeTypeRef);
} else {
$this->assertEquals('string', $nativeTypeRef->getName());
}
$this->assertEquals('string', $nativeTypeRef->getName());
$this->assertStringNotContainsString('\\', get_class($nativeTypeRef));
$this->assertInstanceOf(\ReflectionType::class, $nativeTypeRef);
$this->assertEquals('string or NULL', \Go\ParserReflection\ReflectionType::convertToDisplayType($nativeTypeRef));
Expand Down

0 comments on commit 289f084

Please sign in to comment.