Skip to content

Commit 17eea3c

Browse files
committed
Replace calls to setExpectedException by Pollyfill
1 parent b3c614b commit 17eea3c

File tree

5 files changed

+18
-25
lines changed

5 files changed

+18
-25
lines changed

Tests/Compiler/AutowirePassTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use PHPUnit\Framework\Warning;
16+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1617
use Symfony\Component\Config\FileLocator;
1718
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
1819
use Symfony\Component\DependencyInjection\Compiler\AutowireRequiredMethodsPass;
@@ -33,6 +34,8 @@
3334
*/
3435
class AutowirePassTest extends TestCase
3536
{
37+
use ForwardCompatTestTrait;
38+
3639
public function testProcess()
3740
{
3841
$container = new ContainerBuilder();
@@ -841,12 +844,8 @@ public function testNotWireableCalls($method, $expectedMsg)
841844
$foo->addMethodCall($method, []);
842845
}
843846

844-
if (method_exists($this, 'expectException')) {
845-
$this->expectException(RuntimeException::class);
846-
$this->expectExceptionMessage($expectedMsg);
847-
} else {
848-
$this->setExpectedException(RuntimeException::class, $expectedMsg);
849-
}
847+
$this->expectException(RuntimeException::class);
848+
$this->expectExceptionMessage($expectedMsg);
850849

851850
(new ResolveClassPass())->process($container);
852851
(new AutowireRequiredMethodsPass())->process($container);

Tests/ContainerBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ public function testExtension()
10561056
$container->registerExtension($extension = new \ProjectExtension());
10571057
$this->assertSame($container->getExtension('project'), $extension, '->registerExtension() registers an extension');
10581058

1059-
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('LogicException');
1059+
$this->expectException('LogicException');
10601060
$container->getExtension('no_registered');
10611061
}
10621062

Tests/DefinitionTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\DependencyInjection\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\DependencyInjection\Definition;
1617

1718
class DefinitionTest extends TestCase
1819
{
20+
use ForwardCompatTestTrait;
21+
1922
public function testConstructor()
2023
{
2124
$def = new Definition('stdClass');
@@ -69,12 +72,8 @@ public function testSetGetDecoratedService()
6972

7073
$def = new Definition('stdClass');
7174

72-
if (method_exists($this, 'expectException')) {
73-
$this->expectException('InvalidArgumentException');
74-
$this->expectExceptionMessage('The decorated service inner name for "foo" must be different than the service name itself.');
75-
} else {
76-
$this->setExpectedException('InvalidArgumentException', 'The decorated service inner name for "foo" must be different than the service name itself.');
77-
}
75+
$this->expectException('InvalidArgumentException');
76+
$this->expectExceptionMessage('The decorated service inner name for "foo" must be different than the service name itself.');
7877

7978
$def->setDecoratedService('foo', 'foo');
8079
}

Tests/Dumper/PhpDumperTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,8 @@ public function testCircularReferenceAllowanceForLazyServices()
550550
$dumper = new PhpDumper($container);
551551

552552
$message = 'Circular reference detected for service "foo", path: "foo -> bar -> foo". Try running "composer require symfony/proxy-manager-bridge".';
553-
if (method_exists($this, 'expectException')) {
554-
$this->expectException(ServiceCircularReferenceException::class);
555-
$this->expectExceptionMessage($message);
556-
} else {
557-
$this->setExpectedException(ServiceCircularReferenceException::class, $message);
558-
}
553+
$this->expectException(ServiceCircularReferenceException::class);
554+
$this->expectExceptionMessage($message);
559555

560556
$dumper->dump();
561557
}

Tests/ParameterBag/ParameterBagTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\ParameterBag;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
1617
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
1718
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1819
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
1920

2021
class ParameterBagTest extends TestCase
2122
{
23+
use ForwardCompatTestTrait;
24+
2225
public function testConstructor()
2326
{
2427
$bag = new ParameterBag($parameters = [
@@ -78,12 +81,8 @@ public function testGetThrowParameterNotFoundException($parameterKey, $exception
7881
'fiz' => ['bar' => ['boo' => 12]],
7982
]);
8083

81-
if (method_exists($this, 'expectException')) {
82-
$this->expectException(ParameterNotFoundException::class);
83-
$this->expectExceptionMessage($exceptionMessage);
84-
} else {
85-
$this->setExpectedException(ParameterNotFoundException::class, $exceptionMessage);
86-
}
84+
$this->expectException(ParameterNotFoundException::class);
85+
$this->expectExceptionMessage($exceptionMessage);
8786

8887
$bag->get($parameterKey);
8988
}

0 commit comments

Comments
 (0)