Add type hints

This makes classes inheriting from phpunit classes compatible with phpunit 7.
Fixes #26931
This commit is contained in:
Grégoire Paris 2018-04-21 00:19:27 +02:00
parent 82a95dfb22
commit 6fbcc51566
No known key found for this signature in database
GPG Key ID: 24D48B8012B116BF
6 changed files with 95 additions and 55 deletions

View File

@ -16,7 +16,7 @@ namespace Symfony\Bridge\PhpUnit\Legacy;
*
* @internal
*/
class Command extends \PHPUnit_TextUI_Command
class CommandForV5 extends \PHPUnit_TextUI_Command
{
/**
* {@inheritdoc}

View File

@ -0,0 +1,32 @@
<?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\Legacy;
use PHPUnit\TextUI\Command as BaseCommand;
use PHPUnit\TextUI\TestRunner as BaseRunner;
use Symfony\Bridge\PhpUnit\TextUI\TestRunner;
/**
* {@inheritdoc}
*
* @internal
*/
class CommandForV6 extends BaseCommand
{
/**
* {@inheritdoc}
*/
protected function createRunner(): BaseRunner
{
return new TestRunner($this->arguments['loader']);
}
}

View File

@ -16,7 +16,7 @@ namespace Symfony\Bridge\PhpUnit\Legacy;
*
* @internal
*/
class TestRunner extends \PHPUnit_TextUI_TestRunner
class TestRunnerForV5 extends \PHPUnit_TextUI_TestRunner
{
/**
* {@inheritdoc}

View File

@ -0,0 +1,49 @@
<?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\Legacy;
use PHPUnit\TextUI\TestRunner as BaseRunner;
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
/**
* {@inheritdoc}
*
* @internal
*/
class TestRunnerForV6 extends BaseRunner
{
/**
* {@inheritdoc}
*/
protected function handleConfiguration(array &$arguments): void
{
$listener = new SymfonyTestsListener();
parent::handleConfiguration($arguments);
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
$registeredLocally = false;
foreach ($arguments['listeners'] as $registeredListener) {
if ($registeredListener instanceof SymfonyTestsListener) {
$registeredListener->globalListenerDisabled();
$registeredLocally = true;
break;
}
}
if (!$registeredLocally) {
$arguments['listeners'][] = $listener;
}
}
}

View File

@ -11,24 +11,14 @@
namespace Symfony\Bridge\PhpUnit\TextUI;
use PHPUnit\TextUI\Command as BaseCommand;
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\Command', 'Symfony\Bridge\PhpUnit\TextUI\Command');
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV5', 'Symfony\Bridge\PhpUnit\TextUI\Command');
} else {
/**
* {@inheritdoc}
*
* @internal
*/
class Command extends BaseCommand
class_alias('Symfony\Bridge\PhpUnit\Legacy\CommandForV6', 'Symfony\Bridge\PhpUnit\TextUI\Command');
}
if (false) {
class Command
{
/**
* {@inheritdoc}
*/
protected function createRunner()
{
return new TestRunner($this->arguments['loader']);
}
}
}

View File

@ -11,45 +11,14 @@
namespace Symfony\Bridge\PhpUnit\TextUI;
use PHPUnit\TextUI\TestRunner as BaseRunner;
use Symfony\Bridge\PhpUnit\SymfonyTestsListener;
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunner', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV5', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');
} else {
/**
* {@inheritdoc}
*
* @internal
*/
class TestRunner extends BaseRunner
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV6', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');
}
if (false) {
class TestRunner
{
/**
* {@inheritdoc}
*/
protected function handleConfiguration(array &$arguments)
{
$listener = new SymfonyTestsListener();
$result = parent::handleConfiguration($arguments);
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
$registeredLocally = false;
foreach ($arguments['listeners'] as $registeredListener) {
if ($registeredListener instanceof SymfonyTestsListener) {
$registeredListener->globalListenerDisabled();
$registeredLocally = true;
break;
}
}
if (!$registeredLocally) {
$arguments['listeners'][] = $listener;
}
return $result;
}
}
}