symfony: [PhpUnitBridge] not compatible with latest phpunit

Q A
Bug report? no
Feature request? yes
BC Break report? yes
RFC? yes
Symfony version 3.3.*-dev

I tried to use phpunit-bridge with latest phpunit (^6.0@dev, will be stable next month), it does not work due to changes in phpunit itself.

Error: Class 'PHPUnit_Util_ErrorHandler' not found.

Since phpunit (at last) switched to namespaces, the current class is PHPUnit\Util\ErrorHandler, not PHPUnit_Util_ErrorHandler any more.

I see that supporting this is a BC break, so maybe we could provide a compatibility layer to old phpunit?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 30 (29 by maintainers)

Commits related to this issue

Most upvoted comments

While at lunch 😄 I got an other idea about a different approach to solve this issue:

  • Create classes inside the Symfony\Bridge\PhpUnit\Compat namespace with same name of PHPUnit 6 classes
    • Example: \PHPUnit_Util_ErrorHandler AKA PHPUnit\Util\ErrorHandler becomes Symfony\Bridge\PhpUnit\Compat\Util\ErrorHandler
  • The compat classes will just have the necessary dark magic to extend the right class (I was thinking about use statements wrapped inside an if (class_exist), feel free to suggest other approaches)
  • The compat classes will be already deprecated and dropped in 4.0
  • All usages of PHPUnit classes are replaced by those compat classes
    • Example: \PHPUnit_Util_ErrorHandler::handleError(...); is replaced by ErrorHandler::handleError(...); plus use Symfony\Bridge\PhpUnit\Compat\Util\ErrorHandler;

Advantages:

  • the changes to the code are simple and they are the same as to moving to PHPUnit 6, apart from the use statement
  • The git diff now will be minimal and understandable
  • The git diff later (4.0) will be even smaller, with the deletion of all the compat classes and just a lot of changes to the use statements: use Symfony\Bridge\PhpUnit\Compat\* to use PhpUnit\*

Just a quick update to notice that phpunit 6 is now stable.

I guess it shouldn’t be too hard to make the bridge compatible with PHPUnit 6. I try to look into it tonight.