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

PHPUnit 8.5.27 does not work on PHP 7.2.0-7.2.18 and PHP 7.3.0-7.3.5 #5016

Closed
bshaffer opened this issue Jul 14, 2022 · 5 comments
Closed

PHPUnit 8.5.27 does not work on PHP 7.2.0-7.2.18 and PHP 7.3.0-7.3.5 #5016

bshaffer opened this issue Jul 14, 2022 · 5 comments
Labels
type/change-in-php-requires-adaptation A change in PHP requires a change in PHPUnit

Comments

@bshaffer
Copy link

Q A
PHPUnit version 8.5.27
PHP version 7.3.0
Installation Method Composer

Summary

On PHP 7.3.0 / Ubuntu (note, this is not happening on 7.3.33 / MacOSX), I am getting the following fatal error when running phpunit. The tests are never executed. When I downgrade to v8.5.26, the tests run as expected.

$ vendor/bin/phpunit
PHPUnit 8.5.27 #StandWithUkraine

PHP Fatal error:  Uncaught TypeError: ReflectionClass::getMethods() expects parameter 1 to be int, null given in /workspace/vendor/phpunit/phpunit/src/Util/Reflection.php:45
Stack trace:
#0 /workspace/vendor/phpunit/phpunit/src/Util/Reflection.php(45): ReflectionClass->getMethods(NULL)
#1 /workspace/vendor/phpunit/phpunit/src/Util/Reflection.php(35): PHPUnit\Util\Reflection->filterMethods(Object(ReflectionClass), NULL)
#2 /workspace/vendor/phpunit/phpunit/src/Util/Test.php(513): PHPUnit\Util\Reflection->methodsInTestClass(Object(ReflectionClass))
#3 /workspace/vendor/phpunit/phpunit/src/Framework/TestSuite.php(551): PHPUnit\Util\Test::getHookMethods('Google\\Cloud\\Sa...')
#4 /workspace/vendor/phpunit/phpunit/src/Framework/TestSuite.php(619): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#5 /workspace/vendor/phpunit/phpunit/src/Te in /workspace/php-docs-samples/testing/vendor/phpunit/phpunit/src/Util/Reflection.php on line 45
@bshaffer bshaffer added the type/bug Something is broken label Jul 14, 2022
@sebastianbergmann
Copy link
Owner

I am sorry but support for outdated versions such as 7.3.0 is not something I am able to provide.

@bshaffer
Copy link
Author

That's understandable! Anyone else who runs into it can know that simply downgrading to 8.5.26 fixes the issue.

@sebastianbergmann
Copy link
Owner

I will try my best to look into this, though.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@bshaffer
Copy link
Author

bshaffer commented Jul 14, 2022

  1. Download and start the container for PHP 7.3
docker pull php:7.3.0-zts
docker run -it php:7.3.0-zts /bin/bash
  1. Install git
apt-get update && apt-get install git
  1. Install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
  1. Install phpunit
php composer.phar require phpunit/phpunit:8.5.27
  1. Create an empty testcase
class SomethingTest extends PHPUnit\Framework\TestCase
{
}
  1. Run phpunit 8.5.27
vendor/bin/phpunit SomethingTest.php

You should get the error I posted above:

PHP Fatal error:  Uncaught TypeError: ReflectionClass::getMethods() expects parameter 1 to be int, null given in /vendor/phpunit/phpunit/src/Util/Reflection.php:45

@erdemkose
Copy link

I also have the same problem with PHP 7.2. And I think I have found the reason and in which PHP version it was fixed.

ReflectionClass::getMethods() allows null for the filter but until PHP 7.2.18 and 7.3.5, this is throwing a TypeError if you have declare(strict_types=1); which is the case for PHPUnit.

Nikita fixed it in PHP 7.2.18 and PHP 7.3.5 in a different context. Here you can find the related bug ticket: https://bugs.php.net/bug.php?id=77772.

PHP 7.2.17 - ReflectionClass::getMethods(null): https://3v4l.org/bCJPA#v7.2.17

Fatal error: Uncaught TypeError: ReflectionClass::getMethods() expects parameter 1 to be integer, null given in /in/bCJPA:11
Stack trace:
#0 /in/bCJPA(11): ReflectionClass->getMethods(NULL)
#1 {main}
  thrown in /in/bCJPA on line 11

Process exited with code 255.

PHP 7.2.18 - ReflectionClass::getMethods(null): https://3v4l.org/bCJPA#v7.2.18

Method [ <user> public method test ] {
  @@ /in/bCJPA 6 - 6
}

@sebastianbergmann sebastianbergmann added type/change-in-php-requires-adaptation A change in PHP requires a change in PHPUnit and removed type/bug Something is broken labels Jul 29, 2022
@sebastianbergmann sebastianbergmann changed the title Bug: Fatal Error in latest version of PHPUnit 8 (v8.5.27) on PHP 7.3.0 PHPUnit 8.5.27 does not work on PHP 7.2.0-7.2.18 and PHP 7.3.0-7.3.5 Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/change-in-php-requires-adaptation A change in PHP requires a change in PHPUnit
Projects
None yet
Development

No branches or pull requests

3 participants