Skip to content

[PhpUnitBridge] Add type hints #26994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @internal
*/
class Command extends \PHPUnit_TextUI_Command
class CommandForV5 extends \PHPUnit_TextUI_Command
{
/**
* {@inheritdoc}
Expand Down
32 changes: 32 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/CommandForV6.php
Original file line number Diff line number Diff line change
@@ -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']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @internal
*/
class TestRunner extends \PHPUnit_TextUI_TestRunner
class TestRunnerForV5 extends \PHPUnit_TextUI_TestRunner
{
/**
* {@inheritdoc}
Expand Down
49 changes: 49 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/TestRunnerForV6.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
22 changes: 6 additions & 16 deletions src/Symfony/Bridge/PhpUnit/TextUI/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have create CommandForV7 as well

}

if (false) {
class Command
{
/**
* {@inheritdoc}
*/
protected function createRunner()
{
return new TestRunner($this->arguments['loader']);
}
}
}
43 changes: 6 additions & 37 deletions src/Symfony/Bridge/PhpUnit/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
/**
* {@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;
}
class_alias('Symfony\Bridge\PhpUnit\Legacy\TestRunnerForV6', 'Symfony\Bridge\PhpUnit\TextUI\TestRunner');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have create a TestRunnerForV7 as well.

The TestRunnerForV6 should be the same as the previous defined class (i.e without return typehint) and the TestRunnerForV7 with the return typehint

Copy link
Contributor Author

@greg0ire greg0ire Apr 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have fewer files since adding the type hints even if they are not required is possible, but maybe the naming could be improved *ForV6AndAbove, *ForV5AndBelow?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the Symfony standards regarding naming. I'll let others answer :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the suffix: let use the lowest number

}

return $result;
}
if (false) {
class TestRunner
{
}
}