Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PhpBridge] add PHPUnit 7 support to SymfonyTestsListener #26024

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 4 additions & 2 deletions src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;

if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
// Using an early return instead of a else does not work when using the PHPUnit phar due to some weird PHP behavior (the class
// gets defined without executing the code before it and so the definition is not properly conditional)
if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) {
class_alias('Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '7.0.0', '>=')) {
class_alias('Symfony\Bridge\PhpUnit\SymfonyTestsListenerWithReturnTypes', 'Symfony\Bridge\PhpUnit\SymfonyTestsListener');
} else {
/**
* Collects and replays skipped tests.
Expand Down
69 changes: 69 additions & 0 deletions src/Symfony/Bridge/PhpUnit/SymfonyTestsListenerWithReturnTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\PhpUnit;

use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;

/**
* Collects and replays skipped tests.
*
* (Version of SymfonyTestsListener for PHPUnit 7+, and PHP 7.1+.)
*
* @author Nicolas Grekas <[email protected]>
*
* @final
*/
class SymfonyTestsListenerWithReturnTypes implements TestListener
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be marked internal as people should only interact with SymfonyTestsListener?

Copy link
Member

Choose a reason for hiding this comment

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

yes! see #26139

{
use TestListenerDefaultImplementation;

private $trait;

public function __construct(array $mockedNamespaces = array())
{
$this->trait = new Legacy\SymfonyTestsListenerTrait($mockedNamespaces);
}

public function globalListenerDisabled()
{
$this->trait->globalListenerDisabled();
}

public function startTestSuite(TestSuite $suite): void
{
$this->trait->startTestSuite($suite);
}

public function addSkippedTest(Test $test, \Throwable $t, float $time): void
{
$this->trait->addSkippedTest($test, $t, $time);
}

public function startTest(Test $test): void
{
$this->trait->startTest($test);
}

public function addWarning(Test $test, Warning $e, float $time): void
{
$this->trait->addWarning($test, $e, $time);
}

public function endTest(Test $test, float $time): void
{
$this->trait->endTest($test, $time);
}
}