8000 Add type hints · symfony/symfony@31adcfb · GitHub
[go: up one dir, main page]

Skip to content

Commit 31adcfb

Browse files
committed
Add type hints
This makes classes inheriting from phpunit classes compatible with phpunit 7. Fixes #26931
1 parent 6d9d329 commit 31adcfb

File tree

6 files changed

+186
-46
lines changed

6 files changed

+186
-46
lines changed
Lines changed: 32 additions & 0 deletions
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+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
/**
15+
* CoverageListener adds `@covers <className>` on each test suite when possible
16+
* to make the code coverage more accurate.
17+
*
18+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
19+
*
20+
* @internal
21+
*/
22+
class CoverageListener extends \PHPUnit_Framework_BaseTestListener
23+
{
24+
private $trait;
25+
26+
public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFound = false)
27+
{
28+
$this->trait = new CoverageListenerTrait($sutFqcnResolver, $warningOnSutNotFound);
29+
}
30+
31+
public function startTest(\PHPUnit_Framework_Test $test)
32+
{
33+
$this->trait->startTest($test);
34+
}
35+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
/**
15+
* Collects and replays skipped tests.
16+
*
17+
* @author Nicolas Grekas <p@tchwork.com>
18+
*
19+
* @internal
20+
*/
21+
class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
22+
{
23+
private $trait;
24+
25+
public function __construct(array $mockedNamespaces = array())
26+
{
27+
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
28+
}
29+
30+
public function globalListenerDisabled()
31+
{
32+
$this->trait->globalListenerDisabled();
33+
}
34+
35+
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
36+
{
37+
return $this->trait->startTestSuite($suite);
38+
}
39+
40+
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
41+
{
42+
return $this->trait->addSkippedTest($test, $e, $time);
43+
}
44+
45+
public function startTest(\PHPUnit_Framework_Test $test)
46+
{
47+
return $this->trait->startTest($test);
48+
}
49+
50+
public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
51+
{
52+
return $this->trait->addWarning($test, $e, $time);
53+
}
54+
55+
public function endTest(\PHPUnit_Framework_Test $test, $time)
56+
{
57+
return $this->trait->endTest($test, $time);
58+
}
59+
}
Lines changed: 49 additions & 0 deletions
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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,16 @@
1212
namespace Symfony\Bridge\PhpUnit\TextUI;
1313

1414
use PHPUnit\TextUI\Command as BaseCommand;
15+
use PHPUnit\TextUI\TestRunner as BaseRunner;
1516

1617
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
1718
class_alias('Symfony\Bridge\PhpUnit\Legacy\Command', 'Symfony\Bridge\PhpUnit\TextUI\Command');
1819
} else {
19-
/**
20-
* {@inheritdoc}
21-
*
22-
* @internal
23-
*/
24-
class Command extends BaseCommand
20+
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV6', 'Symfony\Bridge\PhpUnit\TextUI\Command');
21+
}
22+
23+
if (false) {
24+
class Command
2525
{
26-
/**
27-
* {@inheritdoc}
28-
*/
29-
protected function createRunner()
30-
{
31-
return new TestRunner($this->arguments['loader']);
32-
}
3326
}
3427
}

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

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,11 @@
1717
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
1818
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunner', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');
1919
} 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-
}
20+
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV6', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');
21+
}
5122

52-
return $result;
53-
}
23+
if (false) {
24+
class TestRunner
25+
{
5426
}
5527
}

0 commit comments

Comments
 (0)
0