bug #26024 [PhpBridge] add PHPUnit 7 support to SymfonyTestsListener (shieldo)

This PR was squashed before being merged into the 3.4 branch (closes #26024).

Discussion
----------

[PhpBridge] add PHPUnit 7 support to SymfonyTestsListener

| Q             | A
| ------------- | ---
| Branch?       | 3.4 up to 4.0 for bug fixes <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #26017 <!-- #-prefixed issue number(s), if any -->
| License       | MIT

Add support for the new PHPUnit 7 major release to the PHP Bridge for PHPUnit.

I wasn't sure about making a second legacy class here, or the naming of that class - but it seems like something like this would be required. Can re-name if there's a better suggested approach.

Commits
-------

a175a25 [PhpBridge] add PHPUnit 7 support to SymfonyTestsListener
This commit is contained in:
Nicolas Grekas 2018-02-11 12:38:33 +01:00
commit 40fb8434d3
2 changed files with 73 additions and 2 deletions

View File

@ -16,10 +16,12 @@ use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
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)
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');
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '>=')) {
class_alias('Symfony\Bridge\PhpUnit\SymfonyTestsListenerWithReturnTypes', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
} else {
/**
* Collects and replays skipped tests.

View File

@ -0,0 +1,69 @@
<?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;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;
/**
* Collects and replays skipped tests.
*
* (Version of SymfonyTestsListener for PHPUnit 7+, and PHP 7.1+.)
*
* @author Nicolas Grekas <p@tchwork.com>
*
* @final
*/
class SymfonyTestsListenerWithReturnTypes implements TestListener
{
use TestListenerDefaultImplementation;
private $trait;
public function __construct(array $mockedNamespaces = array())
{
$this->trait = new Legacy\SymfonyTestsListenerTrait($mockedNamespaces);
}
public function globalListenerDisabled()
{
$this->trait->globalListenerDisabled();
}
public function startTestSuite(TestSuite $suite): void
{
$this->trait->startTestSuite($suite);
}
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
{
$this->trait->addSkippedTest($test, $t, $time);
}
public function startTest(Test $test): void
{
$this->trait->startTest($test);
}
public function addWarning(Test $test, Warning $e, float $time): void
{
$this->trait->addWarning($test, $e, $time);
}
public function endTest(Test $test, float $time): void
{
$this->trait->endTest($test, $time);
}
}