Skip to content

Commit 35dec94

Browse files
committed
[Tests] Streamline CompiledUrlGenerator tests
1 parent 35703d1 commit 35dec94

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/Symfony/Component/Routing/Tests/Generator/Dumper/CompiledUrlGeneratorDumperTest.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@ public function testDumpWithSimpleLocalizedRoutes()
104104

105105
public function testDumpWithRouteNotFoundLocalizedRoutes()
106106
{
107-
$this->expectException(RouteNotFoundException::class);
108-
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
109107
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
110108

111109
$code = $this->generatorDumper->dump();
112110
file_put_contents($this->testTmpFilepath, $code);
113111

114112
$projectUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext('/app.php'), null, 'pl_PL');
113+
114+
$this->expectException(RouteNotFoundException::class);
115+
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
116+
115117
$projectUrlGenerator->generate('test');
116118
}
117119

@@ -163,22 +165,25 @@ public function testDumpWithTooManyRoutes()
163165

164166
public function testDumpWithoutRoutes()
165167
{
166-
$this->expectException(\InvalidArgumentException::class);
167168
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());
168169

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

172+
$this->expectException(\InvalidArgumentException::class);
173+
171174
$projectUrlGenerator->generate('Test', []);
172175
}
173176

174177
public function testGenerateNonExistingRoute()
175178
{
176-
$this->expectException(RouteNotFoundException::class);
177179
$this->routeCollection->add('Test', new Route('/test'));
178180

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

181183
$projectUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext());
184+
185+
$this->expectException(RouteNotFoundException::class);
186+
182187
$projectUrlGenerator->generate('NonExisting', []);
183188
}
184189

@@ -267,21 +272,18 @@ public function testAliases()
267272

268273
public function testTargetAliasNotExisting()
269274
{
270-
$this->expectException(RouteNotFoundException::class);
271-
272275
$this->routeCollection->addAlias('a', 'not-existing');
273276

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

276-
$compiledUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext());
279+
$this->expectException(RouteNotFoundException::class);
277280

281+
$compiledUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext());
278282
$compiledUrlGenerator->generate('a');
279283
}
280284

281285
public function testTargetAliasWithNamePrefixNotExisting()
282286
{
283-
$this->expectException(RouteNotFoundException::class);
284-
285287
$subCollection = new RouteCollection();
286288
$subCollection->addAlias('a', 'not-existing');
287289
$subCollection->addNamePrefix('sub_');
@@ -290,43 +292,44 @@ public function testTargetAliasWithNamePrefixNotExisting()
290292

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

293-
$compiledUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext());
295+
$this->expectException(RouteNotFoundException::class);
294296

297+
$compiledUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext());
295298
$compiledUrlGenerator->generate('sub_a');
296299
}
297300

298301
public function testCircularReferenceShouldThrowAnException()
299302
{
300-
$this->expectException(RouteCircularReferenceException::class);
301-
$this->expectExceptionMessage('Circular reference detected for route "b", path: "b -> a -> b".');
302-
303303
$this->routeCollection->addAlias('a', 'b');
304304
$this->routeCollection->addAlias('b', 'a');
305305

306+
$this->expectException(RouteCircularReferenceException::class);
307+
$this->expectExceptionMessage('Circular reference detected for route "b", path: "b -> a -> b".');
308+
306309
$this->generatorDumper->dump();
307310
}
308311

309312
public function testDeepCircularReferenceShouldThrowAnException()
310313
{
311-
$this->expectException(RouteCircularReferenceException::class);
312-
$this->expectExceptionMessage('Circular reference detected for route "b", path: "b -> c -> b".');
313-
314314
$this->routeCollection->addAlias('a', 'b');
315315
$this->routeCollection->addAlias('b', 'c');
316316
$this->routeCollection->addAlias('c', 'b');
317317

318+
$this->expectException(RouteCircularReferenceException::class);
319+
$this->expectExceptionMessage('Circular reference detected for route "b", path: "b -> c -> b".');
320+
318321
$this->generatorDumper->dump();
319322
}
320323

321324
public function testIndirectCircularReferenceShouldThrowAnException()
322325
{
323-
$this->expectException(RouteCircularReferenceException::class);
324-
$this->expectExceptionMessage('Circular reference detected for route "b", path: "b -> c -> a -> b".');
325-
326326
$this->routeCollection->addAlias('a', 'b');
327327
$this->routeCollection->addAlias('b', 'c');
328328
$this->routeCollection->addAlias('c', 'a');
329329

330+
$this->expectException(RouteCircularReferenceException::class);
331+
$this->expectExceptionMessage('Circular reference detected for route "b", path: "b -> c -> a -> b".');
332+
330333
$this->generatorDumper->dump();
331334
}
332335

0 commit comments

Comments
 (0)