8000 [PhpUnitBridge] Deprecation bridge for PHPUnit 10.2 by mondrake · Pull Request #50371 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PhpUnitBridge] Deprecation bridge for PHPUnit 10.2 #50371

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 1 commit 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
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private function getConfiguration()
*
* @return string
*/
private static function colorize($str, $red)
public static function colorize($str, $red)
{
if (!self::hasColorSupport()) {
return $str;
Expand Down
15 changes: 12 additions & 3 deletions src/Symfony/Bridge/PhpUnit/ExpectDeprecationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,28 @@
namespace Symfony\Bridge\PhpUnit;

use Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTraitBeforeV8_4;
use Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTraitForV10_2;
use Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTraitForV8_4;

if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '<')) {
if (version_compare(\PHPUnit\Runner\Version::id(), '10.2.0', '>=')) {
/**
* @method void expectDeprecation(string $message)
*/
trait ExpectDeprecationTrait
{
use ExpectDeprecationTraitBeforeV8_4;
use ExpectDeprecationTraitForV10_2;
}
} else {
} elseif (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '>=')) {
/**
* @method void expectDeprecation(string $message)
*/
trait ExpectDeprecationTrait
{
use ExpectDeprecationTraitForV8_4;
}
} else {
trait ExpectDeprecationTrait
{
use ExpectDeprecationTraitBeforeV8_4;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace Symfony\Bridge\PhpUnit\Legacy\EventSubscribers;

use PHPUnit\Event\Application\Finished;
use PHPUnit\Event\Application\FinishedSubscriber;

/**
* @internal
*/
final class ApplicationFinishedSubscriber extends SubscriberBase implements FinishedSubscriber
{
public function notify(Finished $event): void
{
$this->collector()->onApplicationFinished($event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace Symfony\Bridge\PhpUnit\Legacy\EventSubscribers;

use PHPUnit\Event\Test\DeprecationTriggered;
use PHPUnit\Event\Test\DeprecationTriggeredSubscriber as BaseInterface;

/**
* @internal
*/
final class DeprecationTriggeredSubscriber extends SubscriberBase implements BaseInterface
{
public function notify(DeprecationTriggered $event): void
{
$this->collector()->onTriggeredDeprecation(\E_USER_DEPRECATED, $event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace Symfony\Bridge\PhpUnit\Legacy\EventSubscribers;

use PHPUnit\Event\Test\PhpDeprecationTriggered;
use PHPUnit\Event\Test\PhpDeprecationTriggeredSubscriber as BaseInterface;

/**
* @internal
*/
final class PhpDeprecationTriggeredSubscriber extends SubscriberBase implements BaseInterface
{
public function notify(PhpDeprecationTriggered $event): void
{
$this->collector()->onTriggeredDeprecation(\E_DEPRECATED, $event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types=1);

namespace Symfony\Bridge\PhpUnit\Legacy\EventSubscribers;

use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestEventsCollectorForV10_2;

/**
* @internal
*/
abstract class SubscriberBase {

public function __construct(private SymfonyTestEventsCollectorForV10_2 $collector)
{
}

protected function collector(): SymfonyTestEventsCollectorForV10_2
{
return $this->collector;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace Symfony\Bridge\PhpUnit\Legacy\EventSubscribers;

use PHPUnit\Event\Test\Finished;
use PHPUnit\Event\Test\FinishedSubscriber;

/**
* @internal
*/
final class TestFinishedSubscriber extends SubscriberBase implements FinishedSubscriber
{
public function notify(Finished $event): void
{
$this->collector()->onTestFinished($event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types=1);

namespace Symfony\Bridge\PhpUnit\Legacy\EventSubscribers;

use PHPUnit\Event\TestRunner\Finished;
use PHPUnit\Event\TestRunner\FinishedSubscriber;

/**
* @internal
*/
final class TestRunnerFinishedSubscriber extends SubscriberBase implements FinishedSubscriber
{
public function notify(Finished $event): void
{
$this->collector()->onTestRunnerFinished();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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;

/**
* @internal use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead
*/
trait ExpectDeprecationTraitForV10_2
{
public function expectDeprecation(string $message): void
{
// Expected deprecations set by isolated tests need to be written to a file
// so that the test running process can take account of them.
if ($file = getenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE')) {
$this->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
$expectedDeprecations = file_get_contents($file);
if ($expectedDeprecations) {
$expectedDeprecations = array_merge(unserialize($expectedDeprecations), [$message]);
} else {
$expectedDeprecations = [$message];
}
file_put_contents($file, serialize($expectedDeprecations));

return;
}

SymfonyTestEventsCollectorForV10_2::instance()->addExpectedDeprecation($message);
}
}
Loading
0