Skip to content

Commit f29a578

Browse files
Merge branch '3.4' into 4.3
* 3.4: Fix tests Fix deprecated phpunit annotation
2 parents 48337b3 + 53c529c commit f29a578

16 files changed

+105
-198
lines changed

Tests/Annotation/RouteTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@
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

27-
/**
28-
* @expectedException \BadMethodCallException
29-
*/
3028
public function testTryingToSetLocalesDirectly()
3129
{
30+
$this->expectException('BadMethodCallException');
3231
$route = new Route(['locales' => ['nl' => 'bar']]);
3332
}
3433

Tests/Generator/Dumper/CompiledUrlGeneratorDumperTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,10 @@ public function testDumpWithSimpleLocalizedRoutes()
116116
$this->assertEquals('/app.php/foo', $projectUrlGenerator->generate('test'));
117117
}
118118

119-
/**
120-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
121-
* @expectedExceptionMessage Unable to generate a URL for the named route "test" as such route does not exist.
122-
*/
123119
public function testDumpWithRouteNotFoundLocalizedRoutes()
124120
{
121+
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
122+
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
125123
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
126124

127125
$code = $this->generatorDumper->dump();
@@ -178,23 +176,19 @@ public function testDumpWithTooManyRoutes()
178176
$this->assertEquals('/app.php/testing2', $relativeUrlWithoutParameter);
179177
}
180178

181-
/**
182-
* @expectedException \InvalidArgumentException
183-
*/
184179
public function testDumpWithoutRoutes()
185180
{
181+
$this->expectException('InvalidArgumentException');
186182
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());
187183

188184
$projectUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext('/app.php'));
189185

190186
$projectUrlGenerator->generate('Test', []);
191187
}
192188

193-
/**
194-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
195-
*/
196189
public function testGenerateNonExistingRoute()
197190
{
191+
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
198192
$this->routeCollection->add('Test', new Route('/test'));
199193

200194
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());

Tests/Generator/Dumper/PhpGeneratorDumperTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,10 @@ public function testDumpWithSimpleLocalizedRoutes()
125125
$this->assertEquals('/app.php/foo', $projectUrlGenerator->generate('test'));
126126
}
127127

128-
/**
129-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
130-
* @expectedExceptionMessage Unable to generate a URL for the named route "test" as such route does not exist.
131-
*/
132128
public function testDumpWithRouteNotFoundLocalizedRoutes()
133129
{
130+
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
131+
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
134132
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
135133

136134
$code = $this->generatorDumper->dump([
@@ -196,11 +194,9 @@ public function testDumpWithTooManyRoutes()
196194
$this->assertEquals('/app.php/testing2', $relativeUrlWithoutParameter);
197195
}
198196

199-
/**
200-
* @expectedException \InvalidArgumentException
201-
*/
202197
public function testDumpWithoutRoutes()
203198
{
199+
$this->expectException('InvalidArgumentException');
204200
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'WithoutRoutesUrlGenerator']));
205201
include $this->testTmpFilepath;
206202

@@ -209,11 +205,9 @@ public function testDumpWithoutRoutes()
209205
$projectUrlGenerator->generate('Test', []);
210206
}
211207

212-
/**
213-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
214-
*/
215208
public function testGenerateNonExistingRoute()
216209
{
210+
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
217211
$this->routeCollection->add('Test', new Route('/test'));
218212

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

Tests/Generator/UrlGeneratorTest.php

Lines changed: 15 additions & 45 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.
@@ -241,20 +239,16 @@ public function testGenerateWithOverriddenParameterLocaleFromRequestContext()
241239
);
242240
}
243241

244-
/**
245-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
246-
*/
247242
public function testGenerateWithoutRoutes()
248243
{
244+
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
249245
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
250246
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
251247
}
252248

253-
/**
254-
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
255-
*/
256249
public function testGenerateWithInvalidLocale()
257250
{
251+
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
258252
$routes = new RouteCollection();
259253

260254
$route = new Route('');
@@ -273,29 +267,23 @@ public function testGenerateWithInvalidLocale()
273267
$generator->generate($name);
274268
}
275269

276-
/**
277-
* @expectedException \Symfony\Component\Routing\Exception\MissingMandatoryParametersException
278-
*/
279270
public function testGenerateForRouteWithoutMandatoryParameter()
280271
{
272+
$this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');
281273
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
282274
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
283275
}
284276

285-
/**
286-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
287-
*/
288277
public function testGenerateForRouteWithInvalidOptionalParameter()
289278
{
279+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
290280
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
291281
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
292282
}
293283

294-
/**
295-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
296-
*/
297284
public function testGenerateForRouteWithInvalidParameter()
298285
{
286+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
299287
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '1|2']));
300288
$this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL);
301289
}
@@ -327,29 +315,23 @@ public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsC
327315
$this->assertSame('/app.php/testing/bar', $generator->generate('test', ['foo' => 'bar']));
328316
}
329317

330-
/**
331-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
332-
*/
333318
public function testGenerateForRouteWithInvalidMandatoryParameter()
334319
{
320+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
335321
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => 'd+']));
336322
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
337323
}
338324

339-
/**
340-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
341-
*/
342325
public function testGenerateForRouteWithInvalidUtf8Parameter()
343326
{
327+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
344328
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '\pL+'], ['utf8' => true]));
345329
$this->getGenerator($routes)->generate('test', ['foo' => 'abc123'], UrlGeneratorInterface::ABSOLUTE_URL);
346330
}
347331

348-
/**
349-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
350-
*/
351332
public function testRequiredParamAndEmptyPassed()
352333
{
334+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
353335
$routes = $this->getRoutes('test', new Route('/{slug}', [], ['slug' => '.+']));
354336
$this->getGenerator($routes)->generate('test', ['slug' => '']);
355337
}
@@ -509,31 +491,25 @@ public function testImportantVariable()
509491
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index']));
510492
}
511493

512-
/**
513-
* @expectedException \Symfony\Component\Routing\Exception\MissingMandatoryParametersException
514-
*/
515494
public function testImportantVariableWithNoDefault()
516495
{
496+
$this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');
517497
$routes = $this->getRoutes('test', new Route('/{page}.{!_format}'));
518498
$generator = $this->getGenerator($routes);
519499

520500
$generator->generate('test', ['page' => 'index']);
521501
}
522502

523-
/**
524-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
525-
*/
526503
public function testDefaultRequirementOfVariableDisallowsSlash()
527504
{
505+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
528506
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
529507
$this->getGenerator($routes)->generate('test', ['page' => 'index', '_format' => 'sl/ash']);
530508
}
531509

532-
/**
533-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
534-
*/
535510
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
536511
{
512+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
537513
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
538514
$this->getGenerator($routes)->generate('test', ['page' => 'do.t', '_format' => 'html']);
539515
}
@@ -559,29 +535,23 @@ public function testWithHostSameAsContextAndAbsolute()
559535
$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));
560536
}
561537

562-
/**
563-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
564-
*/
565538
public function testUrlWithInvalidParameterInHost()
566539
{
540+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
567541
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
568542
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
569543
}
570544

571-
/**
572-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
573-
*/
574545
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
575546
{
547+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
576548
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'bar'], ['foo' => 'bar'], [], '{foo}.example.com'));
577549
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
578550
}
579551

580-
/**
581-
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
582-
*/
583552
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
584553
{
554+
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
585555
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'baz'], ['foo' => 'bar'], [], '{foo}.example.com'));
586556
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
587557
}

Tests/Loader/AnnotationFileLoaderTest.php

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

48-
/**
49-
* @expectedException \InvalidArgumentException
50-
* @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
51-
*/
5248
public function testLoadFileWithoutStartTag()
5349
{
50+
$this->expectException('InvalidArgumentException');
51+
$this->expectExceptionMessage('Did you forgot to add the "<?php" start tag at the beginning of the file?');
5452
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
5553
}
5654

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
/**
2225
* @group legacy
2326
* @expectedDeprecation Referencing service route loaders with a single colon is deprecated since Symfony 4.1. Use my_route_provider_service::loadRoutes instead.
@@ -67,11 +70,11 @@ public function testLoadCallsServiceAndReturnsCollection()
6770
}
6871

6972
/**
70-
* @expectedException \InvalidArgumentException
7173
* @dataProvider getBadResourceStrings
7274
*/
7375
public function testExceptionWithoutSyntax(string $resourceString): void
7476
{
77+
$this->expectException('InvalidArgumentException');
7578
$loader = new ObjectRouteLoaderForTest();
7679
$loader->load($resourceString);
7780
}
@@ -88,31 +91,25 @@ public function getBadResourceStrings()
8891
];
8992
}
9093

91-
/**
92-
* @expectedException \LogicException
93-
*/
9494
public function testExceptionOnNoObjectReturned()
9595
{
96+
$this->expectException('LogicException');
9697
$loader = new ObjectRouteLoaderForTest();
9798
$loader->loaderMap = ['my_service' => 'NOT_AN_OBJECT'];
9899
$loader->load('my_service::method');
99100
}
100101

101-
/**
102-
* @expectedException \BadMethodCallException
103-
*/
104102
public function testExceptionOnBadMethod()
105103
{
104+
$this->expectException('BadMethodCallException');
106105
$loader = new ObjectRouteLoaderForTest();
107106
$loader->loaderMap = ['my_service' => new \stdClass()];
108107
$loader->load('my_service::method');
109108
}
110109

111-
/**
112-
* @expectedException \LogicException
113-
*/
114110
public function testExceptionOnMethodNotReturningCollection()
115111
{
112+
$this->expectException('LogicException');
116113
$service = $this->getMockBuilder('stdClass')
117114
->setMethods(['loadRoutes'])
118115
->getMock();

0 commit comments

Comments
 (0)