Skip to content

Commit ea25fec

Browse files
bug #26994 [PhpUnitBridge] Add type hints (greg0ire)
This PR was merged into the 3.4 branch. Discussion ---------- [PhpUnitBridge] Add type hints | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no (only changed classes marked as internal) | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26931 | License | MIT | Doc PR | n/a This makes classes inheriting from phpunit classes compatible with phpunit 7. Commits ------- 6fbcc51 Add type hints
2 parents 82a95df + 6fbcc51 commit ea25fec

File tree

6 files changed

+95
-55
lines changed

6 files changed

+95
-55
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/Command.php renamed to src/Symfony/Bridge/PhpUnit/Legacy/CommandForV5.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @internal
1818
*/
19-
class Command extends \PHPUnit_TextUI_Command
19+
class CommandForV5 extends \PHPUnit_TextUI_Command
2020
{
2121
/**
2222
* {@inheritdoc}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Legacy;
13+
14+
use PHPUnit\TextUI\Command as BaseCommand;
15+
use PHPUnit\TextUI\TestRunner as BaseRunner;
16+
use Symfony\Bridge\PhpUnit\TextUI\TestRunner;
17+
18+
/**
19+
* {@inheritdoc}
20+
*
21+
* @internal
22+
*/
23+
class CommandForV6 extends BaseCommand
24+
{
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
protected function createRunner(): BaseRunner
29+
{
30+
return new TestRunner($this->arguments['loader']);
31+
}
32+
}

src/Symfony/Bridge/PhpUnit/Legacy/TestRunner.php renamed to src/Symfony/Bridge/PhpUnit/Legacy/TestRunnerForV5.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @internal
1818
*/
19-
class TestRunner extends \PHPUnit_TextUI_TestRunner
19+
class TestRunnerForV5 extends \PHPUnit_TextUI_TestRunner
2020
{
2121
/**
2222
* {@inheritdoc}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Legacy;
13+
14+
use PHPUnit\TextUI\TestRunner as BaseRunner;
15+
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
16+
17+
/**
18+
* {@inheritdoc}
19+
*
20+
* @internal
21+
*/
22+
class TestRunnerForV6 extends BaseRunner
23+
{
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
protected function handleConfiguration(array &$arguments): void
28+
{
29+
$listener = new SymfonyTestsListener();
30+
31+
parent::handleConfiguration($arguments);
32+
33+
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
34+
35+
$registeredLocally = false;
36+
37+
foreach ($arguments['listeners'] as $registeredListener) {
38+
if ($registeredListener instanceof SymfonyTestsListener) {
39+
$registeredListener->globalListenerDisabled();
40+
$registeredLocally = true;
41+
break;
42+
}
43+
}
44+
45+
if (!$registeredLocally) {
46+
$arguments['listeners'][] = $listener;
47+
}
48+
}
49+
}

src/Symfony/Bridge/PhpUnit/TextUI/Command.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,14 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\TextUI;
1313

14-
use PHPUnit\TextUI\Command as BaseCommand;
15-
1614
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
17-
class_alias('Symfony\Bridge\PhpUnit\Legacy\Command', 'Symfony\Bridge\PhpUnit\TextUI\Command');
15+
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV5', 'Symfony\Bridge\PhpUnit\TextUI\Command');
1816
} else {
19-
/**
20-
* {@inheritdoc}
21-
*
22-
* @internal
23-
*/
24-
class Command extends BaseCommand
17+
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV6', 'Symfony\Bridge\PhpUnit\TextUI\Command');
18+
}
19+
20+
if (false) {
21+
class Command
2522
{
26-
/**
27-
* {@inheritdoc}
28-
*/
29-
protected function createRunner()
30-
{
31-
return new TestRunner($this->arguments['loader']);
32-
}
3323
}
3424
}

src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php

+6-37
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,14 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\TextUI;
1313

14-
use PHPUnit\TextUI\TestRunner as BaseRunner;
15-
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
16-
1714
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
18-
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunner', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');
15+
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV5', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');
1916
} else {
20-
/**
21-
* {@inheritdoc}
22-
*
23-
* @internal
24-
*/
25-
class TestRunner extends BaseRunner
26-
{
27-
/**
28-
* {@inheritdoc}
29-
*/
30-
protected function handleConfiguration(array &$arguments)
31-
{
32-
$listener = new SymfonyTestsListener();
33-
34-
$result = parent::handleConfiguration($arguments);
35-
36-
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
37-
38-
$registeredLocally = false;
39-
40-
foreach ($arguments['listeners'] as $registeredListener) {
41-
if ($registeredListener instanceof SymfonyTestsListener) {
42-
$registeredListener->globalListenerDisabled();
43-
$registeredLocally = true;
44-
break;
45-
}
46-
}
47-
48-
if (!$registeredLocally) {
49-
$arguments['listeners'][] = $listener;
50-
}
17+
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV6', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');
18+
}
5119

52-
return $result;
53-
}
20+
if (false) {
21+
class TestRunner
22+
{
5423
}
5524
}

0 commit comments

Comments
 (0)