Skip to content

Commit 8dd0d55

Browse files
committed
Fix deprecated phpunit annotation
1 parent 17eea3c commit 8dd0d55

38 files changed

+318
-490
lines changed

Tests/ChildDefinitionTest.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
namespace Symfony\Component\DependencyInjection\Tests;
1313

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

1819
class ChildDefinitionTest extends TestCase
1920
{
21+
use ForwardCompatTestTrait;
22+
2023
public function testConstructor()
2124
{
2225
$def = new ChildDefinition('foo');
@@ -90,11 +93,9 @@ public function testSetArgument()
9093
$this->assertSame(['index_0' => 'foo'], $def->getArguments());
9194
}
9295

93-
/**
94-
* @expectedException \InvalidArgumentException
95-
*/
9696
public function testReplaceArgumentShouldRequireIntegerIndex()
9797
{
98+
$this->expectException('InvalidArgumentException');
9899
$def = new ChildDefinition('foo');
99100

100101
$def->replaceArgument('0', 'foo');
@@ -119,11 +120,9 @@ public function testReplaceArgument()
119120
$this->assertSame([0 => 'foo', 1 => 'bar', 'index_1' => 'baz', '$bar' => 'val'], $def->getArguments());
120121
}
121122

122-
/**
123-
* @expectedException \OutOfBoundsException
124-
*/
125123
public function testGetArgumentShouldCheckBounds()
126124
{
125+
$this->expectException('OutOfBoundsException');
127126
$def = new ChildDefinition('foo');
128127

129128
$def->setArguments([0 => 'foo']);
@@ -137,20 +136,16 @@ public function testDefinitionDecoratorAliasExistsForBackwardsCompatibility()
137136
$this->assertInstanceOf(ChildDefinition::class, new DefinitionDecorator('foo'));
138137
}
139138

140-
/**
141-
* @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
142-
*/
143139
public function testCannotCallSetAutoconfigured()
144140
{
141+
$this->expectException('Symfony\Component\DependencyInjection\Exception\BadMethodCallException');
145142
$def = new ChildDefinition('foo');
146143
$def->setAutoconfigured(true);
147144
}
148145

149-
/**
150-
* @expectedException \Symfony\Component\DependencyInjection\Exception\BadMethodCallException
151-
*/
152146
public function testCannotCallSetInstanceofConditionals()
153147
{
148+
$this->expectException('Symfony\Component\DependencyInjection\Exception\BadMethodCallException');
154149
$def = new ChildDefinition('foo');
155150
$def->setInstanceofConditionals(['Foo' => new ChildDefinition('')]);
156151
}

Tests/Compiler/AutoAliasServicePassTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\DependencyInjection\Compiler\AutoAliasServicePass;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718

1819
class AutoAliasServicePassTest extends TestCase
1920
{
20-
/**
21-
* @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
22-
*/
21+
use ForwardCompatTestTrait;
22+
2323
public function testProcessWithMissingParameter()
2424
{
25+
$this->expectException('Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException');
2526
$container = new ContainerBuilder();
2627

2728
$container->register('example')
@@ -31,11 +32,9 @@ public function testProcessWithMissingParameter()
3132
$pass->process($container);
3233
}
3334

34-
/**
35-
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
36-
*/
3735
public function testProcessWithMissingFormat()
3836
{
37+
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
3938
$container = new ContainerBuilder();
4039

4140
$container->register('example')

Tests/Compiler/AutowirePassTest.php

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,10 @@ public function testExceptionsAreStored()
186186
$this->assertCount(1, $pass->getAutowiringExceptions());
187187
}
188188

189-
/**
190-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
191-
* @expectedExceptionMessage Invalid service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public.
192-
*/
193189
public function testPrivateConstructorThrowsAutowireException()
194190
{
191+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
192+
$this->expectExceptionMessage('Invalid service "private_service": constructor of class "Symfony\Component\DependencyInjection\Tests\Compiler\PrivateConstructor" must be public.');
195193
$container = new ContainerBuilder();
196194

197195
$container->autowire('private_service', __NAMESPACE__.'\PrivateConstructor');
@@ -200,12 +198,10 @@ public function testPrivateConstructorThrowsAutowireException()
200198
$pass->process($container);
201199
}
202200

203-
/**
204-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
205-
* @expectedExceptionMessage Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2", "c3".
206-
*/
207201
public function testTypeCollision()
208202
{
203+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
204+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2", "c3".');
209205
$container = new ContainerBuilder();
210206

211207
$container->register('c1', __NAMESPACE__.'\CollisionA');
@@ -218,12 +214,10 @@ public function testTypeCollision()
218214
$pass->process($container);
219215
}
220216

221-
/**
222-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
223-
* @expectedExceptionMessage Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgument::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".
224-
*/
225217
public function testTypeNotGuessable()
226218
{
219+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
220+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgument::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\Foo" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".');
227221
$container = new ContainerBuilder();
228222

229223
$container->register('a1', __NAMESPACE__.'\Foo');
@@ -235,12 +229,10 @@ public function testTypeNotGuessable()
235229
$pass->process($container);
236230
}
237231

238-
/**
239-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
240-
* @expectedExceptionMessage Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgumentForSubclass::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".
241-
*/
242232
public function testTypeNotGuessableWithSubclass()
243233
{
234+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
235+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$k" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotGuessableArgumentForSubclass::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\A" but no such service exists. You should maybe alias this class to one of these existing services: "a1", "a2".');
244236
$container = new ContainerBuilder();
245237

246238
$container->register('a1', __NAMESPACE__.'\B');
@@ -252,12 +244,10 @@ public function testTypeNotGuessableWithSubclass()
252244
$pass->process($container);
253245
}
254246

255-
/**
256-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
257-
* @expectedExceptionMessage Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists.
258-
*/
259247
public function testTypeNotGuessableNoServicesFound()
260248
{
249+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
250+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\CannotBeAutowired::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists.');
261251
$container = new ContainerBuilder();
262252

263253
$aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired');
@@ -376,12 +366,10 @@ public function testDontTriggerAutowiring()
376366
$this->assertCount(0, $container->getDefinition('bar')->getArguments());
377367
}
378368

379-
/**
380-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
381-
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.
382-
*/
383369
public function testClassNotFoundThrowsException()
384370
{
371+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
372+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.');
385373
$container = new ContainerBuilder();
386374

387375
$aDefinition = $container->register('a', __NAMESPACE__.'\BadTypeHintedArgument');
@@ -393,12 +381,10 @@ public function testClassNotFoundThrowsException()
393381
$pass->process($container);
394382
}
395383

396-
/**
397-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
398-
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).
399-
*/
400384
public function testParentClassNotFoundThrowsException()
401385
{
386+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
387+
$this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).');
402388
if (\PHP_VERSION_ID >= 70400) {
403389
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
404390
}
@@ -463,12 +449,10 @@ public function testSomeSpecificArgumentsAreSet()
463449
);
464450
}
465451

466-
/**
467-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
468-
* @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$bar" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" is type-hinted "array", you should configure its value explicitly.
469-
*/
470452
public function testScalarArgsCannotBeAutowired()
471453
{
454+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
455+
$this->expectExceptionMessage('Cannot autowire service "arg_no_type_hint": argument "$bar" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" is type-hinted "array", you should configure its value explicitly.');
472456
$container = new ContainerBuilder();
473457

474458
$container->register(A::class);
@@ -481,12 +465,10 @@ public function testScalarArgsCannotBeAutowired()
481465
(new AutowirePass())->process($container);
482466
}
483467

484-
/**
485-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
486-
* @expectedExceptionMessage Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" has no type-hint, you should configure its value explicitly.
487-
*/
488468
public function testNoTypeArgsCannotBeAutowired()
489469
{
470+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
471+
$this->expectExceptionMessage('Cannot autowire service "arg_no_type_hint": argument "$foo" of method "Symfony\Component\DependencyInjection\Tests\Compiler\MultipleArguments::__construct()" has no type-hint, you should configure its value explicitly.');
490472
$container = new ContainerBuilder();
491473

492474
$container->register(A::class);
@@ -615,11 +597,11 @@ public function testSetterInjection()
615597
}
616598

617599
/**
618-
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
619600
* @exceptedExceptionMessage Invalid service "Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy": method "setLogger()" does not exist.
620601
*/
621602
public function testWithNonExistingSetterAndAutowiring()
622603
{
604+
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
623605
$container = new ContainerBuilder();
624606

625607
$definition = $container->register(CaseSensitiveClass::class, CaseSensitiveClass::class)->setAutowired(true);
@@ -756,12 +738,10 @@ public function testSetterInjectionCollisionThrowsException()
756738
$this->assertSame('Cannot autowire service "setter_injection_collision": argument "$collision" of method "Symfony\Component\DependencyInjection\Tests\Compiler\SetterInjectionCollision::setMultipleInstancesForOneArg()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "c1", "c2".', $e->getMessage());
757739
}
758740

759-
/**
760-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
761-
* @expectedExceptionMessage Cannot autowire service "my_service": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\K::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" but no such service exists. Did you create a class that implements this interface?
762-
*/
763741
public function testInterfaceWithNoImplementationSuggestToWriteOne()
764742
{
743+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
744+
$this->expectExceptionMessage('Cannot autowire service "my_service": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\K::__construct()" references interface "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" but no such service exists. Did you create a class that implements this interface?');
765745
$container = new ContainerBuilder();
766746

767747
$aDefinition = $container->register('my_service', K::class);
@@ -827,10 +807,10 @@ public function testWithFactory()
827807

828808
/**
829809
* @dataProvider provideNotWireableCalls
830-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
831810
*/
832811
public function testNotWireableCalls($method, $expectedMsg)
833812
{
813+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
834814
$container = new ContainerBuilder();
835815

836816
$foo = $container->register('foo', NotWireable::class)->setAutowired(true)
@@ -899,12 +879,10 @@ public function testTypedReferenceDeprecationNotice()
899879
$pass->process($container);
900880
}
901881

902-
/**
903-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
904-
* @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.
905-
*/
906882
public function testExceptionWhenAliasExists()
907883
{
884+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
885+
$this->expectExceptionMessage('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. Try changing the type-hint to "Symfony\Component\DependencyInjection\Tests\Compiler\IInterface" instead.');
908886
$container = new ContainerBuilder();
909887

910888
// multiple I services... but there *is* IInterface available
@@ -919,12 +897,10 @@ public function testExceptionWhenAliasExists()
919897
$pass->process($container);
920898
}
921899

922-
/**
923-
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
924-
* @expectedExceptionMessage Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2".
925-
*/
926900
public function testExceptionWhenAliasDoesNotExist()
927901
{
902+
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
903+
$this->expectExceptionMessage('Cannot autowire service "j": argument "$i" of method "Symfony\Component\DependencyInjection\Tests\Compiler\J::__construct()" references class "Symfony\Component\DependencyInjection\Tests\Compiler\I" but no such service exists. You should maybe alias this class to one of these existing services: "i", "i2".');
928904
if (\PHP_VERSION_ID >= 70400) {
929905
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
930906
}

0 commit comments

Comments
 (0)