Skip to content

Commit de5f0fe

Browse files
committed
[PhpUnitBridge] Fix ExpectDeprecationTrait::expectDeprecation() conflict
1 parent 099868f commit de5f0fe

3 files changed

+93
-12
lines changed

Diff for: ExpectDeprecationTrait.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14-
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait;
14+
use Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTraitBeforeV8_4;
15+
use Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTraitForV8_4;
1516

16-
trait ExpectDeprecationTrait
17-
{
17+
if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '<')) {
18+
trait ExpectDeprecationTrait
19+
{
20+
use ExpectDeprecationTraitBeforeV8_4;
21+
}
22+
} else {
1823
/**
19-
* @param string $message
20-
*
21-
* @return void
24+
* @method void expectDeprecation(string $message)
2225
*/
23-
protected function expectDeprecation($message)
26+
trait ExpectDeprecationTrait
2427
{
25-
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
26-
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
27-
}
28-
29-
SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
28+
use ExpectDeprecationTraitForV8_4;
3029
}
3130
}

Diff for: Legacy/ExpectDeprecationTraitBeforeV8_4.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
13+
14+
/**
15+
* @internal, use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead.
16+
*/
17+
trait ExpectDeprecationTraitBeforeV8_4
18+
{
19+
/**
20+
* @param string $message
21+
*
22+
* @return void
23+
*/
24+
protected function expectDeprecation($message)
25+
{
26+
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
27+
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
28+
}
29+
30+
SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
31+
}
32+
}

Diff for: Legacy/ExpectDeprecationTraitForV8_4.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\PhpUnit\Legacy;
13+
14+
/**
15+
* @internal use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead.
16+
*/
17+
trait ExpectDeprecationTraitForV8_4
18+
{
19+
/**
20+
* @param string $message
21+
*/
22+
public function expectDeprecation(): void
23+
{
24+
if (1 > func_num_args() || !\is_string($message = func_get_arg(0))) {
25+
throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__));
26+
}
27+
28+
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
29+
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
30+
}
31+
32+
SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
33+
}
34+
35+
/**
36+
* @internal use expectDeprecation() instead.
37+
*/
38+
public function expectDeprecationMessage(string $message): void
39+
{
40+
throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait, pass the message to expectDeprecation() instead.', __FUNCTION__));
41+
}
42+
43+
/**
44+
* @internal use expectDeprecation() instead.
45+
*/
46+
public function expectDeprecationMessageMatches(string $regularExpression): void
47+
{
48+
throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait.', __FUNCTION__));
49+
}
50+
}

0 commit comments

Comments
 (0)