Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Step 2 Upgrade] Bump requirement to php 8.0 #125

Merged
merged 19 commits into from Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
5 changes: 3 additions & 2 deletions composer.json
lisachenko marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -22,11 +22,12 @@
}
},
"require": {
"php": ">=7.4",
"php": ">=8.0",
"nikic/php-parser": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^9.0",
"tracy/tracy": "^2.10"
},
"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
5 changes: 3 additions & 2 deletions src/ReflectionType.php
Expand Up @@ -14,6 +14,7 @@

use ReflectionNamedType;
use ReflectionType as BaseReflectionType;
use ReflectionUnionType;

/**
* ReflectionType implementation
Expand Down Expand Up @@ -92,8 +93,8 @@ public static function convertToDisplayType(BaseReflectionType $type)

$displayType = ltrim($displayType, '\\');

if ($type->allowsNull()) {
$displayType .= ' or NULL';
if ($type->allowsNull() && ! $type instanceof ReflectionUnionType) {
$displayType = '?' . $displayType;
}

return $displayType;
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