Skip to content

[PhpUnitBridge] Add compatibility to PHPUnit 9 #35662

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

Closed
Hakihiro opened this issue Feb 10, 2020 · 2 comments
Closed

[PhpUnitBridge] Add compatibility to PHPUnit 9 #35662

Hakihiro opened this issue Feb 10, 2020 · 2 comments

Comments

@Hakihiro
Copy link

Hakihiro commented Feb 10, 2020

Symfony version(s) affected: 4.4.4 (Tested version)

Description
Impossible to use PHPUnit 9 with the actual version of Symfony/PHPUnit-bridge
Because of: sebastianbergmann/phpunit#3914

How to reproduce
In a Symfony project (Version 4.4.4)
Change SYMFONY_PHPUNIT_VERSION to 9 (in phpunit.xml or env var)
Launch your test you will get: PHP Fatal error: Uncaught Error: Call to undefined method PHPUnit\TextUI\Configuration\Configuration::getInstance()

Possible Solution
I suggest to :

  • add a new CommandForV9 file with these changes :
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\TextUI\Command as BaseCommand;
- use PHPUnit\Util\Configuration;
+ use PHPUnit\TextUI\Configuration\Configuration;
+ use PHPUnit\TextUI\Configuration\Registry;
use PHPUnit\TextUI\TestRunner as BaseRunner;
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;

/**
 * {@inheritdoc}
 *
 * @internal
 */
- class CommandForV6 extends BaseCommand
+ class CommandForV9 extends BaseCommand
{
    /**
     * {@inheritdoc}
     */
    protected function createRunner(): BaseRunner
    {
        $this->arguments['listeners'] = isset($this->arguments['listeners']) ? $this->arguments['listeners'] : [];

        $registeredLocally = false;

        foreach ($this->arguments['listeners'] as $registeredListener) {
            if ($registeredListener instanceof SymfonyTestsListener) {
                $registeredListener->globalListenerDisabled();
                $registeredLocally = true;

                break;
            }
        }

        if (isset($this->arguments['configuration'])) {
            $configuration = $this->arguments['configuration'];
            if (!$configuration instanceof Configuration) {
-                $configuration = Configuration::getInstance($this->arguments['configuration']);
+                $configuration = Registry::getInstance()->get($this->arguments['configuration']);
            }
-            foreach ($configuration->getListenerConfiguration() as $registeredListener) {
+            foreach ($configuration->listeners() as $registeredListener) {
-                 if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener['class'], '\\')) {
+                 if ('Symfony\Bridge\PhpUnit\SymfonyTestsListener' === ltrim($registeredListener->className(), '\\')) {
                    $registeredLocally = true;

                    break;
                }
            }
        }

        if (!$registeredLocally) {
            $this->arguments['listeners'][] = new SymfonyTestsListener();
        }

        return parent::createRunner();
    }
}

And add the new file in https://github.com/symfony/phpunit-bridge/blob/master/TextUI/Command.php to switch to the right Command depending on the version.

At this moment I don't know if more changes are required to be fully compatible with PHPUnit 9 but in my case, it's enough to be able to test my code.

@Hakihiro
Copy link
Author

@javiereguiluz Should I build a PR around this subject? Or it's better to discuss it before?

@javiereguiluz
Copy link
Member

This looks like a bug (or unsupported feature) so it will probably be accepted without much debate. So, you may create a PR to let the community discuss about the actual proposed implementation. Thanks!

Hakihiro pushed a commit to Hakihiro/symfony that referenced this issue Feb 14, 2020
Hakihiro pushed a commit to Hakihiro/symfony that referenced this issue Feb 17, 2020
Hakihiro pushed a commit to Hakihiro/symfony that referenced this issue Feb 17, 2020
[PhpUnitBridge] Add compatibility to PHPUnit 9 symfony#35662
nicolas-grekas added a commit that referenced this issue Feb 24, 2020
* 4.4: (25 commits)
  [DoctrineBridge] Use new Types::* constants and support new json type
  [Debug][ErrorHandler] improved deprecation notices for methods new args and return type
  [BrowserKit] Nested file array prevents uploading file
  [ExpressionLanguage] Fixed collisions of character operators with object properties
  [Validator] Remove specific check for Valid targets
  [PhpUnitBridge] Use trait instead of extending deprecated class
  Fix versioned namespace clears
  fix remember me
  Use strict assertion in asset tests
  [DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types
  Do not rely on the current locale when dumping a Graphviz object
  fix typo
  [Ldap] force default network timeout
  [Config] don't throw on missing excluded paths
  Docs: Typo, grammar
  [Validator] Add the missing translations for the Polish ("pl") locale
  [PhpUnitBridge] Add compatibility to PHPUnit 9 #35662
  [Routing] Add locale requirement for localized routes
  [Console] Inline exact-match handling with 4.4
  Set previous exception when rethrown from controller resolver
  ...
nicolas-grekas added a commit that referenced this issue Feb 24, 2020
* 5.0: (28 commits)
  [DoctrineBridge] Use new Types::* constants and support new json type
  Fix bad merge in README of Nexmo Notifier bridge
  [Debug][ErrorHandler] improved deprecation notices for methods new args and return type
  [BrowserKit] Nested file array prevents uploading file
  [ExpressionLanguage] Fixed collisions of character operators with object properties
  remove usage of already deleted Symfony\Component\EventDispatcher\Event
  [Notifier] Add correct tags for NullTransportFactory
  [Validator] Remove specific check for Valid targets
  [PhpUnitBridge] Use trait instead of extending deprecated class
  Fix versioned namespace clears
  fix remember me
  Use strict assertion in asset tests
  [DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types
  Do not rely on the current locale when dumping a Graphviz object
  fix typo
  [Ldap] force default network timeout
  [Config] don't throw on missing excluded paths
  Docs: Typo, grammar
  [Validator] Add the missing translations for the Polish ("pl") locale
  [PhpUnitBridge] Add compatibility to PHPUnit 9 #35662
  ...
PhilETaylor pushed a commit to PhilETaylor/symfony that referenced this issue Sep 6, 2023
* 4.4: (25 commits)
  [DoctrineBridge] Use new Types::* constants and support new json type
  [Debug][ErrorHandler] improved deprecation notices for methods new args and return type
  [BrowserKit] Nested file array prevents uploading file
  [ExpressionLanguage] Fixed collisions of character operators with object properties
  [Validator] Remove specific check for Valid targets
  [PhpUnitBridge] Use trait instead of extending deprecated class
  Fix versioned namespace clears
  fix remember me
  Use strict assertion in asset tests
  [DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types
  Do not rely on the current locale when dumping a Graphviz object
  fix typo
  [Ldap] force default network timeout
  [Config] don't throw on missing excluded paths
  Docs: Typo, grammar
  [Validator] Add the missing translations for the Polish ("pl") locale
  [PhpUnitBridge] Add compatibility to PHPUnit 9 symfony#35662
  [Routing] Add locale requirement for localized routes
  [Console] Inline exact-match handling with 4.4
  Set previous exception when rethrown from controller resolver
  ...
PhilETaylor pushed a commit to PhilETaylor/symfony that referenced this issue Sep 6, 2023
* 5.0: (28 commits)
  [DoctrineBridge] Use new Types::* constants and support new json type
  Fix bad merge in README of Nexmo Notifier bridge
  [Debug][ErrorHandler] improved deprecation notices for methods new args and return type
  [BrowserKit] Nested file array prevents uploading file
  [ExpressionLanguage] Fixed collisions of character operators with object properties
  remove usage of already deleted Symfony\Component\EventDispatcher\Event
  [Notifier] Add correct tags for NullTransportFactory
  [Validator] Remove specific check for Valid targets
  [PhpUnitBridge] Use trait instead of extending deprecated class
  Fix versioned namespace clears
  fix remember me
  Use strict assertion in asset tests
  [DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types
  Do not rely on the current locale when dumping a Graphviz object
  fix typo
  [Ldap] force default network timeout
  [Config] don't throw on missing excluded paths
  Docs: Typo, grammar
  [Validator] Add the missing translations for the Polish ("pl") locale
  [PhpUnitBridge] Add compatibility to PHPUnit 9 symfony#35662
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants