phpunit 6 support
dbu opened this issue · comments
we provide test cases (in src/Test). those tests are not compatible with the new namespaced version of phpunit 6. we should make it compatible and provide a wrapper for phpunit 5.
Maybe using the forward compat layer of PHPUnit 5.4+ is enough? I will look at the code to see if it's feasible.
sounds great. bumping to phpunit 5.4+ would be fine for me.
and thanks for looking into it!
I'm sorry, but I have bad news...
Your test suite (/tests) is easy to be made cross-compatible between PHPUnit 5 and 6, see: Jean85@dd07fc7
I cannot say the same for the tests in src/Test. Cross compatibility is not achievable due to the fact that you are extending a TestListener, which has a broken FC layer:
interface TestListener extends PHPUnit_Framework_TestListener
{
}
This extension doesn't override or change the method's signatures, which are:
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time);
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time);
// etc ...
As you can see, the namespaced interface still (wrongly) uses the non-namespaced classes in its signatures.
We will have to jump from PHPUnit 5 to 6 or duplicate the offending classes for disambiguation.
[EDIT] Also, we have AbstractCacheConstraint
that extends \PHPUnit_Framework_Constraint
which doesn't have an FC layer.
could we provide our own FC layer instead?
Nope, it's completely not doable due to code restriction:
- applying the namespaced classes to the methods' signature will break the interface (we would be restricting the accepted types, breaking Liskov substitution principle)
- removing the types from the arguments will break the interface (PHP does not support contravariance, yet)
That's why I'm advocating class duplication as the only feasible solution; but I still don't know which naming convention should I use for the duplication...
I strongly suggest you to use https://github.com/symfony/phpunit-bridge to ease everything related to PHPUnit.
As I can see, they fixed the same issue with some nice black magic! https://github.com/symfony/phpunit-bridge/blob/3c0efb8609a32890a767bbbd39198a0e92572694/SymfonyTestsListener.php#L19
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
// Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior (the class
// gets defined without executing the code before it and so the definition is not properly conditional)
} else {
/**
* Collects and replays skipped tests.
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*/
class SymfonyTestsListener extends BaseTestListener
{
// ...
Maybe we can do the same!
fixed in #365