Skip to content
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

[PhpUnitBridge] Fix ExpectDeprecationTrait::expectDeprecation() conflict #37153

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/Symfony/Bridge/PhpUnit/ExpectDeprecationTrait.php
Expand Up @@ -11,21 +11,20 @@

namespace Symfony\Bridge\PhpUnit;

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

trait ExpectDeprecationTrait
{
if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '<')) {
trait ExpectDeprecationTrait
{
use ExpectDeprecationTraitBeforeV8_4;
}
} else {
/**
* @param string $message
*
* @return void
* @method void expectDeprecation(string $message)
fancyweb marked this conversation as resolved.
Show resolved Hide resolved
*/
protected function expectDeprecation($message)
trait ExpectDeprecationTrait
{
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
}

SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
use ExpectDeprecationTraitForV8_4;
}
}
@@ -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;

/**
* @internal, use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead.
*/
trait ExpectDeprecationTraitBeforeV8_4
{
/**
* @param string $message
*
* @return void
*/
protected function expectDeprecation($message)
{
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
}

SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
}
}
@@ -0,0 +1,50 @@
<?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 ExpectDeprecationTraitForV8_4
{
/**
* @param string $message
*/
public function expectDeprecation(): void
{
if (1 > func_num_args() || !\is_string($message = func_get_arg(0))) {
throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__));
}

if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
}

SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
}

/**
* @internal use expectDeprecation() instead.
*/
public function expectDeprecationMessage(string $message): void
{
throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait, pass the message to expectDeprecation() instead.', __FUNCTION__));
}

/**
* @internal use expectDeprecation() instead.
*/
public function expectDeprecationMessageMatches(string $regularExpression): void
{
throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait.', __FUNCTION__));
}
}