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-bridge breaks with phpunit 9.1.2 #36499

Closed
jmsche opened this issue Apr 20, 2020 · 21 comments
Closed

phpunit-bridge breaks with phpunit 9.1.2 #36499

jmsche opened this issue Apr 20, 2020 · 21 comments

Comments

@jmsche
Copy link
Contributor

jmsche commented Apr 20, 2020

Hi,

Since phpunit 9.1.2, the bridge fails with this error:

PHP Fatal error:  Uncaught Error: Access to undeclared static property: PHPUnit\Util\Blacklist::$blacklistedClassNames in /dir/bin/.phpunit/phpunit-9.1-0/phpunit:13
Stack trace:
#0 /dir/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php(343): include()
#1 /dir/bin/phpunit(13): require('/home/jmsche/Si...')
#2 {main}
  thrown in /dir/bin/.phpunit/phpunit-9.1-0/phpunit on line 13

After a little research, I found the commit that breaks it: sebastianbergmann/phpunit@2b4d7b8

So phpunit switches from a public static var to a private constant.

@localheinz
Copy link
Contributor

Can confirm.

Running

$ php -v

yields

PHP 7.4.4 (cli) (built: Mar 19 2020 20:12:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.4, Copyright (c), by Zend Technologies

Running

$ composer show | grep phpunit

yields (among others)

phpunit/phpunit                      9.1.2   The PHP Unit Testing framework.
symfony/phpunit-bridge               v5.0.7  Symfony PHPUnit Bridge

Running

$ vendor/bin/phpunit --configuration=phpunit.xml.dist --testsuite=unit

yields

PHP Fatal error:  Uncaught Error: Access to undeclared static property: PHPUnit\Util\Blacklist::$blacklistedClassNames in /Users/am/Sites/foo/bar/backend/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php:51
Stack trace:
#0 /Users/am/Sites/foo/bar/backend/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerForV7.php(34): Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait->__construct(Array)
#1 [internal function]: Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7->__construct()
#2 /Users/am/Sites/foo/bar/backend/vendor/phpunit/phpunit/src/TextUI/Configuration/PHPUnit/ExtensionHandler.php(68): ReflectionClass->newInstance()
#3 /Users/am/Sites/foo/bar/backend/vendor/phpunit/phpunit/src/TextUI/Configuration/PHPUnit/ExtensionHandler.php(39): PHPUnit\TextUI\Configuration\ExtensionHandler->createInstance(Object(PHPUnit\TextUI\Configuration\Extension))
#4 /Users/am/Sites/foo/bar/backend/vendor/phpunit/phpunit/src/TextU in /Users/am/Sites/foo/bar/backend/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php on line 51

Fatal error: Uncaught Error: Access to undeclared static property: PHPUnit\Util\Blacklist::$blacklistedClassNames in /Users/am/Sites/foo/bar/backend/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php:51
Stack trace:
#0 /Users/am/Sites/foo/bar/backend/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerForV7.php(34): Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait->__construct(Array)
#1 [internal function]: Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7->__construct()
#2 /Users/am/Sites/foo/bar/backend/vendor/phpunit/phpunit/src/TextUI/Configuration/PHPUnit/ExtensionHandler.php(68): ReflectionClass->newInstance()
#3 /Users/am/Sites/foo/bar/backend/vendor/phpunit/phpunit/src/TextUI/Configuration/PHPUnit/ExtensionHandler.php(39): PHPUnit\TextUI\Configuration\ExtensionHandler->createInstance(Object(PHPUnit\TextUI\Configuration\Extension))
#4 /Users/am/Sites/foo/bar/backend/vendor/phpunit/phpunit/src/TextU in /Users/am/Sites/foo/bar/backend/vendor/symfony/phpunit-bridge/Legacy/SymfonyTestsListenerTrait.php on line 51

@localheinz
Copy link
Contributor

@jmsche

I would not go as far as blaming phpunit/phpunit for breaking changes here - PHPUnit\Util\Blacklist has been marked as @internal 15 months ago.

@nicolas-grekas
Copy link
Member

Can anyone look into an alternative implementation?
If none is possible, a report to phpunit might still have to be considered.

@jmsche
Copy link
Contributor Author

jmsche commented Apr 20, 2020

@localheinz I'm not blaming phpunit, I know the class is marked as internal.
Not sure why you assumed I blame phpunit for this.
I only searched for the reason why it breaks.

@luchaninov
Copy link
Contributor

For those who came here for quick solution: set in composer.json fixed phpunit version. "phpunit/phpunit": "9.1.1" (not "phpunit/phpunit": "^9.0")

@greg0ire
Copy link
Contributor

greg0ire commented Apr 21, 2020

For those like I that are wondering what this blacklist is about, 3777da5(from #21135) a shows that it is about removing lines about the bridge from stack traces

@Hakihiro
Copy link

Hakihiro commented Apr 21, 2020

For those who came here for quick solution: set in composer.json fixed phpunit version. "phpunit/phpunit": "9.1.1" (not "phpunit/phpunit": "^9.0")

In addition to this message, the quick solution is to downgrade PHPUnit to the highest compatible version 9.1.1.

Can we use src/Symfony/Bridge/PhpUnit/Blacklist.php (found here commit)inside src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php instead of \PHPUnit_Util_Blacklist::$blacklistedClassNames ?

Well, my bad I can't find the file in the current version.

@Jean85
Copy link
Contributor

Jean85 commented Apr 22, 2020

Sebastian was so kind to suggest a solution on his side: sebastianbergmann/phpunit#4186 (comment)

@fabpot fabpot closed this as completed Apr 24, 2020
fabpot added a commit that referenced this issue Apr 24, 2020
This PR was merged into the 3.4 branch.

Discussion
----------

[PhpUnitBridge] fix compatibility with phpunit 9

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36499
| License       | MIT
| Doc PR        | none

See related issue

Commits
-------

e27ed28 fix compatibility with phpunit 9
fabpot added a commit that referenced this issue Apr 25, 2020
This PR was merged into the 3.4 branch.

Discussion
----------

[PhpUnitBridge] Improve dirname usage

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36499
| License       | MIT

This is a very small performance improvement on top of #36539

Commits
-------

e721cfd Improve dirname usage
kudesnic pushed a commit to kudesnic/symfony that referenced this issue Apr 27, 2020
Issue symfony#36499
Error appears in symfony 5 when we use phpunit 9.1.3 and symfony/phpunit-bridge 5.0.7
@4d4ch4u32
Copy link

I'm using Symfony 4.4, I got the same error.

@martinssipenko
Copy link
Contributor

I'm using Symfony 4.4, I got the same error.

There hasn't been a release yet.

@4d4ch4u32
Copy link

I see. But I need to use ist. How can I change the version with the Symfony phpunit bridge?

@greg0ire
Copy link
Contributor

You can use this constraint: "phpunit/phpunit": "^9.0,<9.1.2",

@4d4ch4u32
Copy link

Where? phpunit will be installed by running the command ./bin/phpunit from the phpunit-bridge-bundle the first time.

@greg0ire
Copy link
Contributor

Oh then you need to use SYMFONY_PHPUNIT_VERSION

@4d4ch4u32
Copy link

4d4ch4u32 commented Apr 27, 2020

I got error messages with the following phpunit versions:

  • 9.1.3
  • 9.0.0
  • 8.5.4
  • 7.5.20

Is there any version that works?

@andrew-demb
Copy link
Contributor

@antondachauer as mentioned in the comment above, phpunit 9.1.1 works.

For those who came here for quick solution: set in composer.json fixed phpunit version. "phpunit/phpunit": "9.1.1" (not "phpunit/phpunit": "^9.0")

@4d4ch4u32
Copy link

No, 9.1.1 also does not work.

[27-Apr-2020 12:40:32 Europe/Berlin] PHP Fatal error:  Uncaught TypeError: version_compare() expects parameter 3 to be string, object given in /var/www/app/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuite/TestSuiteMapper.php:34
Stack trace:
#0 /var/www/app/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuite/TestSuiteMapper.php(34): version_compare('7.3.16', '7.3.16', Object(PHPUnit\Util\VersionComparisonOperator))
#1 /var/www/app/bin/.phpunit/phpunit-9.1.1-0/src/TextUI/Command.php(395): PHPUnit\TextUI\Configuration\TestSuiteMapper->map(Object(PHPUnit\TextUI\Configuration\TestSuiteCollection), '')
#2 /var/www/app/bin/.phpunit/phpunit-9.1.1-0/src/TextUI/Command.php(71): PHPUnit\TextUI\Command->handleArguments(Array)
#3 /var/www/app/bin/.phpunit/phpunit-9.1.1-0/src/TextUI/Command.php(63): PHPUnit\TextUI\Command->run(Array, true)
#4 /var/www/app/bin/.phpunit/phpunit-9.1.1-0/phpunit(17): PHPUnit\TextUI\Command::main()
#5 /var/www/app/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php(343): include('/var/www/app/bi...')
#6 /var/www/app/bin/phpunit(13): in /var/www/app/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuite/TestSuiteMapper.php on line 34

@bizley
Copy link

bizley commented Apr 27, 2020

This is weird. <server name="SYMFONY_PHPUNIT_VERSION" value="9.1.1" /> in phpunit.xml definitely works for me.

@4d4ch4u32
Copy link

... but not for me. Here's my phpunit.xml content:

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="bin/.phpunit/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="config/bootstrap.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <server name="APP_ENV" value="test" force="true" />
        <server name="SHELL_VERBOSITY" value="-1" />
        <server name="SYMFONY_PHPUNIT_REMOVE" value="" />
        <server name="SYMFONY_PHPUNIT_VERSION" value="9.1.1" />
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>Tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>

    <listeners>
        <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
    </listeners>
</phpunit>

@bizley
Copy link

bizley commented Apr 27, 2020

Looks like you have PHPUnit installed in bin and in vendor at the same time.

@4d4ch4u32
Copy link

4d4ch4u32 commented Apr 27, 2020

Ok, I've removed the vendor phpunit package. Now it works with version 9.1.1. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.