Skip to content

Commit 40fb843

Browse files
bug symfony#26024 [PhpBridge] add PHPUnit 7 support to SymfonyTestsListener (shieldo)
This PR was squashed before being merged into the 3.4 branch (closes symfony#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 | symfony#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
2 parents 4c0befc + a175a25 commit 40fb843

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
use PHPUnit\Framework\TestSuite;
1717
use PHPUnit\Framework\Warning;
1818

19-
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
20-
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
2119
// Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior (the class
2220
// gets defined without executing the code before it and so the definition is not properly conditional)
21+
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
22+
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
23+
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '>=')) {
24+
class_alias('Symfony\Bridge\PhpUnit\SymfonyTestsListenerWithReturnTypes', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
2325
} else {
2426
/**
2527
* Collects and replays skipped tests.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit;
13+
14+
use PHPUnit\Framework\Test;
15+
use PHPUnit\Framework\TestListener;
16+
use PHPUnit\Framework\TestListenerDefaultImplementation;
17+
use PHPUnit\Framework\TestSuite;
18+
use PHPUnit\Framework\Warning;
19+
20+
/**
21+
* Collects and replays skipped tests.
22+
*
23+
* (Version of SymfonyTestsListener for PHPUnit 7+, and PHP 7.1+.)
24+
*
25+
* @author Nicolas Grekas <[email protected]>
26+
*
27+
* @final
28+
*/
29+
class SymfonyTestsListenerWithReturnTypes implements TestListener
30+
{
31+
use TestListenerDefaultImplementation;
32+
33+
private $trait;
34+
35+
public function __construct(array $mockedNamespaces = array())
36+
{
37+
$this->trait = new Legacy\SymfonyTestsListenerTrait($mockedNamespaces);
38+
}
39+
40+
public function globalListenerDisabled()
41+
{
42+
$this->trait->globalListenerDisabled();
43+
}
44+
45+
public function startTestSuite(TestSuite $suite): void
46+
{
47+
$this->trait->startTestSuite($suite);
48+
}
49+
50+
public function addSkippedTest(Test $test, \Throwable $t, float $time): void
51+
{
52+
$this->trait->addSkippedTest($test, $t, $time);
53+
}
54+
55+
public function startTest(Test $test): void
56+
{
57+
$this->trait->startTest($test);
58+
}
59+
60+
public function addWarning(Test $test, Warning $e, float $time): void
61+
{
62+
$this->trait->addWarning($test, $e, $time);
63+
}
64+
65+
public function endTest(Test $test, float $time): void
66+
{
67+
$this->trait->endTest($test, $time);
68+
}
69+
}

0 commit comments

Comments
 (0)