diff options
author | Remi Collet <remi@remirepo.net> | 2021-03-26 14:33:33 +0100 |
---|---|---|
committer | Remi Collet <remi@remirepo.net> | 2021-03-26 14:33:33 +0100 |
commit | 3da825e4b89c0ba27f168c0123d3de68cedafd1c (patch) | |
tree | 9065ec2f14da74b80dd1b954034b72c3be26a0da | |
parent | d347607b5ed5ab3db6ef6aab1e70a454cac31d13 (diff) |
more fix for PHP 8
-rw-r--r-- | phpunit7-php8.patch | 184 | ||||
-rw-r--r-- | phpunit7.spec | 22 |
2 files changed, 178 insertions, 28 deletions
diff --git a/phpunit7-php8.patch b/phpunit7-php8.patch index d2a286e..abe16d5 100644 --- a/phpunit7-php8.patch +++ b/phpunit7-php8.patch @@ -1,6 +1,6 @@ diff -up ./src/Framework/MockObject/Builder/Match.php.php8 ./src/Framework/MockObject/Builder/Match.php --- ./src/Framework/MockObject/Builder/Match.php.php8 2020-01-08 09:45:45.000000000 +0100 -+++ ./src/Framework/MockObject/Builder/Match.php 2021-03-24 14:30:25.218737051 +0100 ++++ ./src/Framework/MockObject/Builder/Match.php 2021-03-26 14:22:46.505856216 +0100 @@ -12,7 +12,7 @@ namespace PHPUnit\Framework\MockObject\B /** * Builder interface for invocation order matches. @@ -12,7 +12,7 @@ diff -up ./src/Framework/MockObject/Builder/Match.php.php8 ./src/Framework/MockO * Defines the expectation which must occur before the current is valid. diff -up ./src/Framework/MockObject/Builder/NamespaceMatch.php.php8 ./src/Framework/MockObject/Builder/NamespaceMatch.php --- ./src/Framework/MockObject/Builder/NamespaceMatch.php.php8 2020-01-08 09:45:45.000000000 +0100 -+++ ./src/Framework/MockObject/Builder/NamespaceMatch.php 2021-03-24 14:30:25.218737051 +0100 ++++ ./src/Framework/MockObject/Builder/NamespaceMatch.php 2021-03-26 14:22:46.505856216 +0100 @@ -33,5 +33,5 @@ interface NamespaceMatch * @param string $id The identification of the match builder * @param Match $builder The builder which is being registered @@ -22,7 +22,7 @@ diff -up ./src/Framework/MockObject/Builder/NamespaceMatch.php.php8 ./src/Framew } diff -up ./src/Framework/MockObject/Builder/ParametersMatch.php.php8 ./src/Framework/MockObject/Builder/ParametersMatch.php --- ./src/Framework/MockObject/Builder/ParametersMatch.php.php8 2020-01-08 09:45:45.000000000 +0100 -+++ ./src/Framework/MockObject/Builder/ParametersMatch.php 2021-03-24 14:30:25.218737051 +0100 ++++ ./src/Framework/MockObject/Builder/ParametersMatch.php 2021-03-26 14:22:46.505856216 +0100 @@ -14,7 +14,7 @@ use PHPUnit\Framework\MockObject\Matcher /** * Builder interface for parameter matchers. @@ -32,10 +32,9 @@ diff -up ./src/Framework/MockObject/Builder/ParametersMatch.php.php8 ./src/Frame { /** * Sets the parameters to match for, each parameter to this function will -diff -up ./src/Framework/MockObject/Generator.php.php8 ./src/Framework/MockObject/Generator.php diff -up ./src/Framework/MockObject/InvocationMocker.php.php8 ./src/Framework/MockObject/InvocationMocker.php --- ./src/Framework/MockObject/InvocationMocker.php.php8 2020-01-08 09:45:45.000000000 +0100 -+++ ./src/Framework/MockObject/InvocationMocker.php 2021-03-24 14:30:25.218737051 +0100 ++++ ./src/Framework/MockObject/InvocationMocker.php 2021-03-26 14:22:46.505856216 +0100 @@ -12,7 +12,7 @@ namespace PHPUnit\Framework\MockObject; use Exception; use PHPUnit\Framework\ExpectationFailedException; @@ -56,24 +55,169 @@ diff -up ./src/Framework/MockObject/InvocationMocker.php.php8 ./src/Framework/Mo throw new RuntimeException( diff -up ./src/Framework/MockObject/MockMethod.php.php8 ./src/Framework/MockObject/MockMethod.php --- ./src/Framework/MockObject/MockMethod.php.php8 2020-01-08 09:45:45.000000000 +0100 -+++ ./src/Framework/MockObject/MockMethod.php 2021-03-24 14:30:25.218737051 +0100 -@@ -301,11 +301,11 @@ final class MockMethod - $nullable = '?'; ++++ ./src/Framework/MockObject/MockMethod.php 2021-03-26 14:23:49.737575694 +0100 +@@ -12,6 +12,7 @@ namespace PHPUnit\Framework\MockObject; + use ReflectionClass; + use ReflectionException; + use ReflectionMethod; ++use ReflectionNamedType; + use Text_Template; + + final class MockMethod +@@ -269,7 +270,7 @@ final class MockMethod + * + * @throws RuntimeException + */ +- private static function getMethodParameters(ReflectionMethod $method, bool $forCall = false): string ++ private static function getMethodParametersForDeclaration(ReflectionMethod $method): string + { + $parameters = []; + +@@ -283,63 +284,38 @@ final class MockMethod + $name = '$arg' . $i; + } + +- if ($parameter->isVariadic()) { +- if ($forCall) { +- continue; +- } +- +- $name = '...' . $name; +- } +- + $nullable = ''; + $default = ''; + $reference = ''; + $typeDeclaration = ''; ++ $type = null; ++ $typeName = null; + +- if (!$forCall) { +- if ($parameter->hasType() && $parameter->allowsNull()) { +- $nullable = '?'; ++ if ($parameter->hasType()) { ++ $type = $parameter->getType(); ++ ++ if ($type instanceof ReflectionNamedType) { ++ $typeName = $type->getName(); } ++ } ++ ++ if ($parameter->isVariadic()) { ++ $name = '...' . $name; ++ } elseif ($parameter->isDefaultValueAvailable()) { ++ $default = ' = ' . var_export($parameter->getDefaultValue(), true); ++ } elseif ($parameter->isOptional()) { ++ $default = ' = null'; ++ } - if ($parameter->hasType() && $parameter->getType()->getName() !== 'self') { -+ if ($parameter->hasType() && (($t=$parameter->getType()) instanceof ReflectionNamedType) && $t->getName() !== 'self') { - $typeDeclaration = $parameter->getType()->getName() . ' '; - } else { - try { +- $typeDeclaration = $parameter->getType()->getName() . ' '; +- } else { +- try { - $class = $parameter->getClass(); -+ $class = @$parameter->getClass(); - } catch (ReflectionException $e) { - throw new RuntimeException( - \sprintf( +- } catch (ReflectionException $e) { +- throw new RuntimeException( +- \sprintf( +- 'Cannot mock %s::%s() because a class or ' . +- 'interface used in the signature is not loaded', +- $method->getDeclaringClass()->getName(), +- $method->getName() +- ), +- 0, +- $e +- ); +- } +- +- if ($class !== null) { +- $typeDeclaration = $class->getName() . ' '; +- } ++ if ($type !== null) { ++ if ($typeName !== 'mixed' && $parameter->allowsNull()) { ++ $nullable = '?'; + } + +- if (!$parameter->isVariadic()) { +- if ($parameter->isDefaultValueAvailable()) { +- try { +- $value = \var_export($parameter->getDefaultValue(), true); +- } catch (\ReflectionException $e) { +- throw new RuntimeException( +- $e->getMessage(), +- (int) $e->getCode(), +- $e +- ); +- } +- +- $default = ' = ' . $value; +- } elseif ($parameter->isOptional()) { +- $default = ' = null'; +- } ++ if ($typeName === 'self') { ++ $typeDeclaration = $method->getDeclaringClass()->getName() . ' '; ++ } elseif ($typeName !== null) { ++ $typeDeclaration = $typeName . ' '; + } + } + +@@ -350,6 +326,53 @@ final class MockMethod + $parameters[] = $nullable . $typeDeclaration . $reference . $name . $default; + } + +- return \implode(', ', $parameters); ++ return implode(', ', $parameters); ++ } ++ ++ /** ++ * Returns the parameters of a function or method. ++ * ++ * @throws ReflectionException ++ */ ++ private static function getMethodParametersForCall(ReflectionMethod $method): string ++ { ++ $parameters = []; ++ ++ foreach ($method->getParameters() as $i => $parameter) { ++ $name = '$' . $parameter->getName(); ++ ++ /* Note: PHP extensions may use empty names for reference arguments ++ * or "..." for methods taking a variable number of arguments. ++ */ ++ if ($name === '$' || $name === '$...') { ++ $name = '$arg' . $i; ++ } ++ ++ if ($parameter->isVariadic()) { ++ continue; ++ } ++ ++ if ($parameter->isPassedByReference()) { ++ $parameters[] = '&' . $name; ++ } else { ++ $parameters[] = $name; ++ } ++ } ++ ++ return implode(', ', $parameters); ++ } ++ ++ ++ /** ++ * Returns the parameters of a function or method. ++ * ++ * @throws RuntimeException ++ */ ++ private static function getMethodParameters(ReflectionMethod $method, bool $forCall = false): string ++ { ++ if ($forCall) { ++ return self::getMethodParametersForCall($method); ++ } ++ return self::getMethodParametersForDeclaration($method); + } + } diff -up ./tests/_files/SingletonClass.php.php8 ./tests/_files/SingletonClass.php ---- ./tests/_files/SingletonClass.php.php8 2021-03-24 14:33:54.292214558 +0100 -+++ ./tests/_files/SingletonClass.php 2021-03-24 14:37:50.093575868 +0100 +--- ./tests/_files/SingletonClass.php.php8 2020-01-08 09:45:45.000000000 +0100 ++++ ./tests/_files/SingletonClass.php 2021-03-26 14:22:46.505856216 +0100 @@ -17,11 +17,11 @@ class SingletonClass { } @@ -90,7 +234,7 @@ diff -up ./tests/_files/SingletonClass.php.php8 ./tests/_files/SingletonClass.ph diff -up ./tests/unit/Framework/Constraint/IsTypeTest.php.php8 ./tests/unit/Framework/Constraint/IsTypeTest.php --- ./tests/unit/Framework/Constraint/IsTypeTest.php.php8 2020-01-08 09:45:45.000000000 +0100 -+++ ./tests/unit/Framework/Constraint/IsTypeTest.php 2021-03-24 14:30:25.219737049 +0100 ++++ ./tests/unit/Framework/Constraint/IsTypeTest.php 2021-03-26 14:22:46.505856216 +0100 @@ -74,7 +74,7 @@ EOF $this->assertTrue($constraint->evaluate($resource, '', true)); @@ -102,7 +246,7 @@ diff -up ./tests/unit/Framework/Constraint/IsTypeTest.php.php8 ./tests/unit/Fram public function resources() diff -up ./tests/unit/Framework/Constraint/JsonMatchesErrorMessageProviderTest.php.php8 ./tests/unit/Framework/Constraint/JsonMatchesErrorMessageProviderTest.php --- ./tests/unit/Framework/Constraint/JsonMatchesErrorMessageProviderTest.php.php8 2020-01-08 09:45:45.000000000 +0100 -+++ ./tests/unit/Framework/Constraint/JsonMatchesErrorMessageProviderTest.php 2021-03-24 14:30:25.219737049 +0100 ++++ ./tests/unit/Framework/Constraint/JsonMatchesErrorMessageProviderTest.php 2021-03-26 14:22:46.505856216 +0100 @@ -17,7 +17,7 @@ class JsonMatchesErrorMessageProviderTes { return [ diff --git a/phpunit7.spec b/phpunit7.spec index f34df11..3d45be7 100644 --- a/phpunit7.spec +++ b/phpunit7.spec @@ -28,7 +28,7 @@ Name: %{pk_project}%{ver_major} Version: %{ver_major}.%{ver_minor}.%{ver_patch} -Release: 4%{?dist} +Release: 5%{?dist} Summary: The PHP Unit Testing framework version %{ver_major} License: BSD @@ -264,14 +264,17 @@ for cmd in php php73 php74 php80; do if which $cmd; then OPT="--testsuite=unit --no-coverage" VER=$($cmd -r 'echo PHP_VERSION_ID;'); - if [ $VER -ge 80000 ]; then - FILTER="testStaticAttributesBackupPre|testResourceTypeCanBeAsserted|testNotResourceTypeCanBeAsserted|testCreateMockFromWsdl" - FILTER="$FILTER|testCreateNamespacedMockFromWsdl|testCreateTwoMocksOfOneWsdlFile|testCreateMockOfWsdlFileWithSpecialChars" - FILTER="$FILTER|testCreateTestForConstructorlessTestClass|testCountTraversable|testConstraintTraversableCheckForObjectIdentityForDefaultCase" - OPT="$OPT --filter '^((?!($FILTER)).)*$'" - elif [ $VER -ge 70400 ]; then - OPT="$OPT --filter '^((?!(testStaticAttributesBackupPre)).)*$'" + if [ $VER -ge 70400 ]; then + FILTER="testStaticAttributesBackupPre" + fi + if [ $VER -ge 80000 ]; then + FILTER="$FILTER|testResourceTypeCanBeAsserted|testNotResourceTypeCanBeAsserted" + FILTER="$FILTER|testCountTraversable|testConstraintTraversableCheckForObjectIdentityForDefaultCase" + OPT="$OPT --filter '^((?!($FILTER)).)*$'" + fi + if [ -n "$FILTER" ]; then + OPT="$OPT --filter '^((?!($FILTER)).)*$'" fi $cmd ./phpunit $OPT --verbose || ret=1 fi @@ -290,6 +293,9 @@ exit $ret %changelog +* Fri Mar 26 2021 Remi Collet <remi@remirepo.net> - 7.5.20-5 +- more fix for PHP 8 + * Thu Mar 25 2021 Remi Collet <remi@remirepo.net> - 7.5.20-4 - recommend using a supported version |