Skip to content

Commit 7b647c6

Browse files
committed
Fix deprecated phpunit annotation
1 parent b01eaca commit 7b647c6

16 files changed

+93
-164
lines changed

Tests/Annotation/RouteTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
namespace Symfony\Component\Routing\Tests\Annotation;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Routing\Annotation\Route;
1617

1718
class RouteTest extends TestCase
1819
{
19-
/**
20-
* @expectedException \BadMethodCallException
21-
*/
20+
use ForwardCompatTestTrait;
21+
2222
public function testInvalidRouteParameter()
2323
{
24+
$this->expectException('BadMethodCallException');
2425
$route = new Route(['foo' => 'bar']);
2526
}
2627

Tests/Generator/Dumper/PhpGeneratorDumperTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,9 @@ public function testDumpWithTooManyRoutes()
118118
$this->assertEquals('/app.php/testing2', $relativeUrlWithoutParameter);
119119
}
120120

121-
/**
122-
* @expectedException \InvalidArgumentException
123-
*/
124121
public function testDumpWithoutRoutes()
125122
{
123+
$this->expectException('InvalidArgumentException');
126124
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'WithoutRoutesUrlGenerator']));
127125
include $this->testTmpFilepath;
128126

@@ -131,11 +129,9 @@ public function testDumpWithoutRoutes()
131129
$projectUrlGenerator->generate('Test', []);
132130
}
133131

134-
/**
135-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
136-
*/
137132
public function testGenerateNonExistingRoute()
138133
{
134+
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
139135
$this->routeCollection->add('Test', new Route('/test'));
140136

141137
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'NonExistingRoutesUrlGenerator']));

Tests/Generator/UrlGeneratorTest.php

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,9 @@ public function testRelativeUrlWithNullParameter()
7979
$this->assertEquals('/app.php/testing', $url);
8080
}
8181

82-
/**
83-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
84-
*/
8582
public function testRelativeUrlWithNullParameterButNotOptional()
8683
{
84+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
8785
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', ['foo' => null]));
8886
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
8987
// Generating path "/testing//bar" would be wrong as matching this route would fail.
@@ -165,38 +163,30 @@ public function testGlobalParameterHasHigherPriorityThanDefault()
165163
$this->assertSame('/app.php/de', $url);
166164
}
167165

168-
/**
169-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
170-
*/
171166
public function testGenerateWithoutRoutes()
172167
{
168+
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
173169
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
174170
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
175171
}
176172

177-
/**
178-
* @expectedException \Symfony\Component\Routing\Exception\MissingMandatoryParametersException
179-
*/
180173
public function testGenerateForRouteWithoutMandatoryParameter()
181174
{
175+
$this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');
182176
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
183177
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
184178
}
185179

186-
/**
187-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
188-
*/
189180
public function testGenerateForRouteWithInvalidOptionalParameter()
190181
{
182+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
191183
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
192184
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
193185
}
194186

195-
/**
196-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
197-
*/
198187
public function testGenerateForRouteWithInvalidParameter()
199188
{
189+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
200190
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '1|2']));
201191
$this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL);
202192
}
@@ -228,29 +218,23 @@ public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsC
228218
$this->assertSame('/app.php/testing/bar', $generator->generate('test', ['foo' => 'bar']));
229219
}
230220

231-
/**
232-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
233-
*/
234221
public function testGenerateForRouteWithInvalidMandatoryParameter()
235222
{
223+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
236224
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => 'd+']));
237225
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
238226
}
239227

240-
/**
241-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
242-
*/
243228
public function testGenerateForRouteWithInvalidUtf8Parameter()
244229
{
230+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
245231
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '\pL+'], ['utf8' => true]));
246232
$this->getGenerator($routes)->generate('test', ['foo' => 'abc123'], UrlGeneratorInterface::ABSOLUTE_URL);
247233
}
248234

249-
/**
250-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
251-
*/
252235
public function testRequiredParamAndEmptyPassed()
253236
{
237+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
254238
$routes = $this->getRoutes('test', new Route('/{slug}', [], ['slug' => '.+']));
255239
$this->getGenerator($routes)->generate('test', ['slug' => '']);
256240
}
@@ -400,20 +384,16 @@ public function testDefaultRequirementOfVariable()
400384
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index', '_format' => 'mobile.html']));
401385
}
402386

403-
/**
404-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
405-
*/
406387
public function testDefaultRequirementOfVariableDisallowsSlash()
407388
{
389+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
408390
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
409391
$this->getGenerator($routes)->generate('test', ['page' => 'index', '_format' => 'sl/ash']);
410392
}
411393

412-
/**
413-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
414-
*/
415394
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
416395
{
396+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
417397
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
418398
$this->getGenerator($routes)->generate('test', ['page' => 'do.t', '_format' => 'html']);
419399
}
@@ -439,29 +419,23 @@ public function testWithHostSameAsContextAndAbsolute()
439419
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL));
440420
}
441421

442-
/**
443-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
444-
*/
445422
public function testUrlWithInvalidParameterInHost()
446423
{
424+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
447425
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
448426
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
449427
}
450428

451-
/**
452-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
453-
*/
454429
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
455430
{
431+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
456432
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'bar'], ['foo' => 'bar'], [], '{foo}.example.com'));
457433
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
458434
}
459435

460-
/**
461-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
462-
*/
463436
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
464437
{
438+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
465439
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'baz'], ['foo' => 'bar'], [], '{foo}.example.com'));
466440
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
467441
}

Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,15 @@ private function doSetUp()
2929
$this->loader = $this->getClassLoader($this->reader);
3030
}
3131

32-
/**
33-
* @expectedException \InvalidArgumentException
34-
*/
3532
public function testLoadMissingClass()
3633
{
34+
$this->expectException('InvalidArgumentException');
3735
$this->loader->load('MissingClass');
3836
}
3937

40-
/**
41-
* @expectedException \InvalidArgumentException
42-
*/
4338
public function testLoadAbstractClass()
4439
{
40+
$this->expectException('InvalidArgumentException');
4541
$this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\AbstractClass');
4642
}
4743

Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ public function testLoadTraitWithClassConstant()
4848
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
4949
}
5050

51-
/**
52-
* @expectedException \InvalidArgumentException
53-
* @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
54-
*/
5551
public function testLoadFileWithoutStartTag()
5652
{
53+
$this->expectException('InvalidArgumentException');
54+
$this->expectExceptionMessage('Did you forgot to add the "<?php" start tag at the beginning of the file?');
5755
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
5856
}
5957

Tests/Loader/ObjectRouteLoaderTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
namespace Symfony\Component\Routing\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Routing\Loader\ObjectRouteLoader;
1617
use Symfony\Component\Routing\Route;
1718
use Symfony\Component\Routing\RouteCollection;
1819

1920
class ObjectRouteLoaderTest extends TestCase
2021
{
22+
use ForwardCompatTestTrait;
23+
2124
public function testLoadCallsServiceAndReturnsCollection()
2225
{
2326
$loader = new ObjectRouteLoaderForTest();
@@ -41,11 +44,11 @@ public function testLoadCallsServiceAndReturnsCollection()
4144
}
4245

4346
/**
44-
* @expectedException \InvalidArgumentException
4547
* @dataProvider getBadResourceStrings
4648
*/
4749
public function testExceptionWithoutSyntax($resourceString)
4850
{
51+
$this->expectException('InvalidArgumentException');
4952
$loader = new ObjectRouteLoaderForTest();
5053
$loader->load($resourceString);
5154
}
@@ -59,31 +62,25 @@ public function getBadResourceStrings()
5962
];
6063
}
6164

62-
/**
63-
* @expectedException \LogicException
64-
*/
6565
public function testExceptionOnNoObjectReturned()
6666
{
67+
$this->expectException('LogicException');
6768
$loader = new ObjectRouteLoaderForTest();
6869
$loader->loaderMap = ['my_service' => 'NOT_AN_OBJECT'];
6970
$loader->load('my_service:method');
7071
}
7172

72-
/**
73-
* @expectedException \BadMethodCallException
74-
*/
7573
public function testExceptionOnBadMethod()
7674
{
75+
$this->expectException('BadMethodCallException');
7776
$loader = new ObjectRouteLoaderForTest();
7877
$loader->loaderMap = ['my_service' => new \stdClass()];
7978
$loader->load('my_service:method');
8079
}
8180

82-
/**
83-
* @expectedException \LogicException
84-
*/
8581
public function testExceptionOnMethodNotReturningCollection()
8682
{
83+
$this->expectException('LogicException');
8784
$service = $this->getMockBuilder('stdClass')
8885
->setMethods(['loadRoutes'])
8986
->getMock();

Tests/Loader/XmlFileLoaderTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Config\FileLocator;
1617
use Symfony\Component\Routing\Loader\XmlFileLoader;
1718
use Symfony\Component\Routing\Tests\Fixtures\CustomXmlFileLoader;
1819

1920
class XmlFileLoaderTest extends TestCase
2021
{
22+
use ForwardCompatTestTrait;
23+
2124
public function testSupports()
2225
{
2326
$loader = new XmlFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
@@ -104,21 +107,21 @@ public function testUtf8Route()
104107
}
105108

106109
/**
107-
* @expectedException \InvalidArgumentException
108110
* @dataProvider getPathsToInvalidFiles
109111
*/
110112
public function testLoadThrowsExceptionWithInvalidFile($filePath)
111113
{
114+
$this->expectException('InvalidArgumentException');
112115
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
113116
$loader->load($filePath);
114117
}
115118

116119
/**
117-
* @expectedException \InvalidArgumentException
118120
* @dataProvider getPathsToInvalidFiles
119121
*/
120122
public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation($filePath)
121123
{
124+
$this->expectException('InvalidArgumentException');
122125
$loader = new CustomXmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
123126
$loader->load($filePath);
124127
}
@@ -128,12 +131,10 @@ public function getPathsToInvalidFiles()
128131
return [['nonvalidnode.xml'], ['nonvalidroute.xml'], ['nonvalid.xml'], ['missing_id.xml'], ['missing_path.xml']];
129132
}
130133

131-
/**
132-
* @expectedException \InvalidArgumentException
133-
* @expectedExceptionMessage Document types are not allowed.
134-
*/
135134
public function testDocTypeIsNotAllowed()
136135
{
136+
$this->expectException('InvalidArgumentException');
137+
$this->expectExceptionMessage('Document types are not allowed.');
137138
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
138139
$loader->load('withdoctype.xml');
139140
}
@@ -338,12 +339,10 @@ public function testLoadRouteWithControllerSetInDefaults()
338339
$this->assertSame('AppBundle:Blog:list', $route->getDefault('_controller'));
339340
}
340341

341-
/**
342-
* @expectedException \InvalidArgumentException
343-
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for "app_blog"/
344-
*/
345342
public function testOverrideControllerInDefaults()
346343
{
344+
$this->expectException('InvalidArgumentException');
345+
$this->expectExceptionMessageRegExp('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for "app_blog"/');
347346
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
348347
$loader->load('override_defaults.xml');
349348
}
@@ -372,12 +371,10 @@ public function provideFilesImportingRoutesWithControllers()
372371
yield ['import__controller.xml'];
373372
}
374373

375-
/**
376-
* @expectedException \InvalidArgumentException
377-
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for the "import" tag/
378-
*/
379374
public function testImportWithOverriddenController()
380375
{
376+
$this->expectException('InvalidArgumentException');
377+
$this->expectExceptionMessageRegExp('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for the "import" tag/');
381378
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
382379
$loader->load('import_override_defaults.xml');
383380
}

0 commit comments

Comments
 (0)