Skip to content

Commit 2c4b231

Browse files
committed
Fix deprecated phpunit annotation
1 parent 2044bea commit 2c4b231

25 files changed

+126
-156
lines changed

Tests/Command/RouterDebugCommandTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
1617
use Symfony\Bundle\FrameworkBundle\Console\Application;
1718
use Symfony\Component\Console\Tester\CommandTester;
@@ -21,6 +22,8 @@
2122

2223
class RouterDebugCommandTest extends TestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
public function testDebugAllRoutes()
2528
{
2629
$tester = $this->createCommandTester();
@@ -39,11 +42,9 @@ public function testDebugSingleRoute()
3942
$this->assertContains('Route Name | foo', $tester->getDisplay());
4043
}
4144

42-
/**
43-
* @expectedException \InvalidArgumentException
44-
*/
4545
public function testDebugInvalidRoute()
4646
{
47+
$this->expectException('InvalidArgumentException');
4748
$this->createCommandTester()->execute(['name' => 'test']);
4849
}
4950

Tests/Command/TranslationDebugCommandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ public function testDebugCustomDirectory()
9797
$this->assertRegExp('/unused/', $tester->getDisplay());
9898
}
9999

100-
/**
101-
* @expectedException \InvalidArgumentException
102-
*/
103100
public function testDebugInvalidDirectory()
104101
{
102+
$this->expectException('InvalidArgumentException');
105103
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
106104
$kernel->expects($this->once())
107105
->method('getBundle')

Tests/Command/YamlLintCommandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ public function testLintIncorrectFile()
6161
$this->assertContains('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
6262
}
6363

64-
/**
65-
* @expectedException \RuntimeException
66-
*/
6764
public function testLintFileNotReadable()
6865
{
66+
$this->expectException('RuntimeException');
6967
$tester = $this->createCommandTester();
7068
$filename = $this->createFile('');
7169
unlink($filename);

Tests/Controller/ControllerTraitTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait;
1516
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1617
use Symfony\Component\DependencyInjection\Container;
@@ -31,6 +32,8 @@
3132

3233
abstract class ControllerTraitTest extends TestCase
3334
{
35+
use ForwardCompatTestTrait;
36+
3437
abstract protected function createController();
3538

3639
public function testForward()
@@ -87,12 +90,10 @@ public function testGetUserWithEmptyTokenStorage()
8790
$this->assertNull($controller->getUser());
8891
}
8992

90-
/**
91-
* @expectedException \LogicException
92-
* @expectedExceptionMessage The SecurityBundle is not registered in your application.
93-
*/
9493
public function testGetUserWithEmptyContainer()
9594
{
95+
$this->expectException('LogicException');
96+
$this->expectExceptionMessage('The SecurityBundle is not registered in your application.');
9697
$controller = $this->createController();
9798
$controller->setContainer(new Container());
9899

@@ -274,11 +275,9 @@ public function testFileFromPathWithCustomizedFileName()
274275
$this->assertContains('test.php', $response->headers->get('content-disposition'));
275276
}
276277

277-
/**
278-
* @expectedException \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
279-
*/
280278
public function testFileWhichDoesNotExist()
281279
{
280+
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
282281
$controller = $this->createController();
283282

284283
/* @var BinaryFileResponse $response */
@@ -299,11 +298,9 @@ public function testIsGranted()
299298
$this->assertTrue($controller->isGranted('foo'));
300299
}
301300

302-
/**
303-
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
304-
*/
305301
public function testdenyAccessUnlessGranted()
306302
{
303+
$this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
307304
$authorizationChecker = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')->getMock();
308305
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(false);
309306

Tests/Controller/TemplateControllerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
1313

14+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1415
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
1516
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
1617
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
@@ -20,6 +21,8 @@
2021
*/
2122
class TemplateControllerTest extends TestCase
2223
{
24+
use ForwardCompatTestTrait;
25+
2326
public function testTwig()
2427
{
2528
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
@@ -77,12 +80,10 @@ public function testLegacyTemplating()
7780
$this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
7881
}
7982

80-
/**
81-
* @expectedException \LogicException
82-
* @expectedExceptionMessage You can not use the TemplateController if the Templating Component or the Twig Bundle are not available.
83-
*/
8483
public function testNoTwigNorTemplating()
8584
{
85+
$this->expectException('LogicException');
86+
$this->expectExceptionMessage('You can not use the TemplateController if the Templating Component or the Twig Bundle are not available.');
8687
$controller = new TemplateController();
8788

8889
$controller->templateAction('mytemplate')->getContent();

Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
1617
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -22,6 +23,8 @@
2223
*/
2324
class AddConsoleCommandPassTest extends TestCase
2425
{
26+
use ForwardCompatTestTrait;
27+
2528
/**
2629
* @dataProvider visibilityProvider
2730
*/
@@ -63,12 +66,10 @@ public function visibilityProvider()
6366
];
6467
}
6568

66-
/**
67-
* @expectedException \InvalidArgumentException
68-
* @expectedExceptionMessage The service "my-command" tagged "console.command" must not be abstract.
69-
*/
7069
public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
7170
{
71+
$this->expectException('InvalidArgumentException');
72+
$this->expectExceptionMessage('The service "my-command" tagged "console.command" must not be abstract.');
7273
$container = new ContainerBuilder();
7374
$container->addCompilerPass(new AddConsoleCommandPass());
7475

@@ -80,12 +81,10 @@ public function testProcessThrowAnExceptionIfTheServiceIsAbstract()
8081
$container->compile();
8182
}
8283

83-
/**
84-
* @expectedException \InvalidArgumentException
85-
* @expectedExceptionMessage The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".
86-
*/
8784
public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
8885
{
86+
$this->expectException('InvalidArgumentException');
87+
$this->expectExceptionMessage('The service "my-command" tagged "console.command" must be a subclass of "Symfony\Component\Console\Command\Command".');
8988
$container = new ContainerBuilder();
9089
$container->addCompilerPass(new AddConsoleCommandPass());
9190

Tests/DependencyInjection/Compiler/AddConstraintValidatorsPassTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
1617
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -24,6 +25,8 @@
2425
*/
2526
class AddConstraintValidatorsPassTest extends TestCase
2627
{
28+
use ForwardCompatTestTrait;
29+
2730
public function testThatConstraintValidatorServicesAreProcessed()
2831
{
2932
$container = new ContainerBuilder();
@@ -46,12 +49,10 @@ public function testThatConstraintValidatorServicesAreProcessed()
4649
$this->assertEquals($expected, $container->getDefinition((string) $validatorFactory->getArgument(0)));
4750
}
4851

49-
/**
50-
* @expectedException \InvalidArgumentException
51-
* @expectedExceptionMessage The service "my_abstract_constraint_validator" tagged "validator.constraint_validator" must not be abstract.
52-
*/
5352
public function testAbstractConstraintValidator()
5453
{
54+
$this->expectException('InvalidArgumentException');
55+
$this->expectExceptionMessage('The service "my_abstract_constraint_validator" tagged "validator.constraint_validator" must not be abstract.');
5556
$container = new ContainerBuilder();
5657
$validatorFactory = $container->register('validator.validator_factory')
5758
->addArgument([]);

Tests/DependencyInjection/Compiler/CachePoolPassTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,10 @@ public function testArgsAreReplaced()
9696
$this->assertSame(3, $cachePool->getArgument(2));
9797
}
9898

99-
/**
100-
* @expectedException \InvalidArgumentException
101-
* @expectedExceptionMessage Invalid "cache.pool" tag for service "app.cache_pool": accepted attributes are
102-
*/
10399
public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
104100
{
101+
$this->expectException('InvalidArgumentException');
102+
$this->expectExceptionMessage('Invalid "cache.pool" tag for service "app.cache_pool": accepted attributes are');
105103
$container = new ContainerBuilder();
106104
$container->setParameter('kernel.debug', false);
107105
$container->setParameter('kernel.name', 'app');

Tests/DependencyInjection/Compiler/CachePoolPrunerPassTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPrunerPass;
1617
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1718
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
@@ -21,6 +22,8 @@
2122

2223
class CachePoolPrunerPassTest extends TestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
public function testCompilerPassReplacesCommandArgument()
2528
{
2629
$container = new ContainerBuilder();
@@ -56,12 +59,10 @@ public function testCompilePassIsIgnoredIfCommandDoesNotExist()
5659
$this->assertCount($aliasesBefore, $container->getAliases());
5760
}
5861

59-
/**
60-
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
61-
* @expectedExceptionMessage Class "Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\NotFound" used for service "pool.not-found" cannot be found.
62-
*/
6362
public function testCompilerPassThrowsOnInvalidDefinitionClass()
6463
{
64+
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
65+
$this->expectExceptionMessage('Class "Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\NotFound" used for service "pool.not-found" cannot be found.');
6566
$container = new ContainerBuilder();
6667
$container->register('console.command.cache_pool_prune')->addArgument([]);
6768
$container->register('pool.not-found', NotFound::class)->addTag('cache.pool');

Tests/DependencyInjection/Compiler/FormPassTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Definition;
@@ -24,6 +25,8 @@
2425
*/
2526
class FormPassTest extends TestCase
2627
{
28+
use ForwardCompatTestTrait;
29+
2730
public function testDoNothingIfFormExtensionNotLoaded()
2831
{
2932
$container = new ContainerBuilder();
@@ -124,12 +127,10 @@ public function addTaggedTypeExtensionsDataProvider()
124127
];
125128
}
126129

127-
/**
128-
* @expectedException \InvalidArgumentException
129-
* @expectedExceptionMessage extended-type attribute, none was configured for the "my.type_extension" service
130-
*/
131130
public function testAddTaggedFormTypeExtensionWithoutExtendedTypeAttribute()
132131
{
132+
$this->expectException('InvalidArgumentException');
133+
$this->expectExceptionMessage('extended-type attribute, none was configured for the "my.type_extension" service');
133134
$container = new ContainerBuilder();
134135
$container->addCompilerPass(new FormPass());
135136

Tests/DependencyInjection/Compiler/ProfilerPassTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

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

1819
class ProfilerPassTest extends TestCase
1920
{
21+
use ForwardCompatTestTrait;
22+
2023
/**
2124
* Tests that collectors that specify a template but no "id" will throw
2225
* an exception (both are needed if the template is specified).
2326
*
2427
* Thus, a fully-valid tag looks something like this:
2528
*
2629
* <tag name="data_collector" template="YourBundle:Collector:templatename" id="your_collector_name" />
27-
*
28-
* @expectedException \InvalidArgumentException
2930
*/
3031
public function testTemplateNoIdThrowsException()
3132
{
33+
$this->expectException('InvalidArgumentException');
3234
$builder = new ContainerBuilder();
3335
$builder->register('profiler', 'ProfilerClass');
3436
$builder->register('my_collector_service')

Tests/DependencyInjection/Compiler/SerializerPassTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Reference;
@@ -25,25 +26,23 @@
2526
*/
2627
class SerializerPassTest extends TestCase
2728
{
28-
/**
29-
* @expectedException \RuntimeException
30-
* @expectedExceptionMessage You must tag at least one service as "serializer.normalizer" to use the "serializer" service
31-
*/
29+
use ForwardCompatTestTrait;
30+
3231
public function testThrowExceptionWhenNoNormalizers()
3332
{
33+
$this->expectException('RuntimeException');
34+
$this->expectExceptionMessage('You must tag at least one service as "serializer.normalizer" to use the "serializer" service');
3435
$container = new ContainerBuilder();
3536
$container->register('serializer');
3637

3738
$serializerPass = new SerializerPass();
3839
$serializerPass->process($container);
3940
}
4041

41-
/**
42-
* @expectedException \RuntimeException
43-
* @expectedExceptionMessage You must tag at least one service as "serializer.encoder" to use the "serializer" service
44-
*/
4542
public function testThrowExceptionWhenNoEncoders()
4643
{
44+
$this->expectException('RuntimeException');
45+
$this->expectExceptionMessage('You must tag at least one service as "serializer.encoder" to use the "serializer" service');
4746
$container = new ContainerBuilder();
4847
$container->register('serializer')
4948
->addArgument([])

0 commit comments

Comments
 (0)