Skip to content

Commit 78eeb0d

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: Use ::class keyword when possible
2 parents ed2b759 + 80d5743 commit 78eeb0d

17 files changed

+88
-88
lines changed

Matcher/Dumper/CompiledUrlMatcherDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ private function compileRoute(Route $route, string $name, $vars, bool $hasTraili
446446
private function getExpressionLanguage(): ExpressionLanguage
447447
{
448448
if (null === $this->expressionLanguage) {
449-
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
449+
if (!class_exists(ExpressionLanguage::class)) {
450450
throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
451451
}
452452
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);

Matcher/UrlMatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ protected function mergeDefaults(array $params, array $defaults)
253253
protected function getExpressionLanguage()
254254
{
255255
if (null === $this->expressionLanguage) {
256-
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
256+
if (!class_exists(ExpressionLanguage::class)) {
257257
throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
258258
}
259259
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);
@@ -267,7 +267,7 @@ protected function getExpressionLanguage()
267267
*/
268268
protected function createRequest(string $pathinfo): ?Request
269269
{
270-
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
270+
if (!class_exists(Request::class)) {
271271
return null;
272272
}
273273

Tests/Annotation/RouteTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class RouteTest extends TestCase
1818
{
1919
public function testInvalidRouteParameter()
2020
{
21-
$this->expectException('BadMethodCallException');
21+
$this->expectException(\BadMethodCallException::class);
2222
new Route(['foo' => 'bar']);
2323
}
2424

2525
public function testTryingToSetLocalesDirectly()
2626
{
27-
$this->expectException('BadMethodCallException');
27+
$this->expectException(\BadMethodCallException::class);
2828
new Route(['locales' => ['nl' => 'bar']]);
2929
}
3030

Tests/Generator/Dumper/CompiledUrlGeneratorDumperTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testDumpWithSimpleLocalizedRoutes()
118118

119119
public function testDumpWithRouteNotFoundLocalizedRoutes()
120120
{
121-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
121+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
122122
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
123123
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
124124

@@ -178,7 +178,7 @@ public function testDumpWithTooManyRoutes()
178178

179179
public function testDumpWithoutRoutes()
180180
{
181-
$this->expectException('InvalidArgumentException');
181+
$this->expectException(\InvalidArgumentException::class);
182182
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());
183183

184184
$projectUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext('/app.php'));
@@ -188,7 +188,7 @@ public function testDumpWithoutRoutes()
188188

189189
public function testGenerateNonExistingRoute()
190190
{
191-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
191+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
192192
$this->routeCollection->add('Test', new Route('/test'));
193193

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

Tests/Generator/UrlGeneratorTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testRelativeUrlWithNullParameter()
7878

7979
public function testRelativeUrlWithNullParameterButNotOptional()
8080
{
81-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
81+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
8282
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', ['foo' => null]));
8383
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
8484
// Generating path "/testing//bar" would be wrong as matching this route would fail.
@@ -264,14 +264,14 @@ public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl()
264264

265265
public function testGenerateWithoutRoutes()
266266
{
267-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
267+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
268268
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
269269
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
270270
}
271271

272272
public function testGenerateWithInvalidLocale()
273273
{
274-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
274+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
275275
$routes = new RouteCollection();
276276

277277
$route = new Route('');
@@ -293,21 +293,21 @@ public function testGenerateWithInvalidLocale()
293293

294294
public function testGenerateForRouteWithoutMandatoryParameter()
295295
{
296-
$this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');
296+
$this->expectException(\Symfony\Component\Routing\Exception\MissingMandatoryParametersException::class);
297297
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
298298
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
299299
}
300300

301301
public function testGenerateForRouteWithInvalidOptionalParameter()
302302
{
303-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
303+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
304304
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
305305
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
306306
}
307307

308308
public function testGenerateForRouteWithInvalidParameter()
309309
{
310-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
310+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
311311
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '1|2']));
312312
$this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL);
313313
}
@@ -323,7 +323,7 @@ public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
323323
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
324324
{
325325
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
326-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
326+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
327327
$logger->expects($this->once())
328328
->method('error');
329329
$generator = $this->getGenerator($routes, [], $logger);
@@ -341,21 +341,21 @@ public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsC
341341

342342
public function testGenerateForRouteWithInvalidMandatoryParameter()
343343
{
344-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
344+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
345345
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => 'd+']));
346346
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
347347
}
348348

349349
public function testGenerateForRouteWithInvalidUtf8Parameter()
350350
{
351-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
351+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
352352
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '\pL+'], ['utf8' => true]));
353353
$this->getGenerator($routes)->generate('test', ['foo' => 'abc123'], UrlGeneratorInterface::ABSOLUTE_URL);
354354
}
355355

356356
public function testRequiredParamAndEmptyPassed()
357357
{
358-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
358+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
359359
$routes = $this->getRoutes('test', new Route('/{slug}', [], ['slug' => '.+']));
360360
$this->getGenerator($routes)->generate('test', ['slug' => '']);
361361
}
@@ -476,7 +476,7 @@ public function testAdjacentVariables()
476476

477477
// The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything
478478
// and following optional variables like _format could never match.
479-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
479+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
480480
$generator->generate('test', ['x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml']);
481481
}
482482

@@ -517,7 +517,7 @@ public function testImportantVariable()
517517

518518
public function testImportantVariableWithNoDefault()
519519
{
520-
$this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');
520+
$this->expectException(\Symfony\Component\Routing\Exception\MissingMandatoryParametersException::class);
521521
$routes = $this->getRoutes('test', new Route('/{page}.{!_format}'));
522522
$generator = $this->getGenerator($routes);
523523

@@ -526,14 +526,14 @@ public function testImportantVariableWithNoDefault()
526526

527527
public function testDefaultRequirementOfVariableDisallowsSlash()
528528
{
529-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
529+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
530530
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
531531
$this->getGenerator($routes)->generate('test', ['page' => 'index', '_format' => 'sl/ash']);
532532
}
533533

534534
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
535535
{
536-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
536+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
537537
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
538538
$this->getGenerator($routes)->generate('test', ['page' => 'do.t', '_format' => 'html']);
539539
}
@@ -561,21 +561,21 @@ public function testWithHostSameAsContextAndAbsolute()
561561

562562
public function testUrlWithInvalidParameterInHost()
563563
{
564-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
564+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
565565
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
566566
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
567567
}
568568

569569
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
570570
{
571-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
571+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
572572
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'bar'], ['foo' => 'bar'], [], '{foo}.example.com'));
573573
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
574574
}
575575

576576
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
577577
{
578-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
578+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
579579
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'baz'], ['foo' => 'bar'], [], '{foo}.example.com'));
580580
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
581581
}

Tests/Loader/AbstractAnnotationLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ abstract class AbstractAnnotationLoaderTest extends TestCase
1717
{
1818
public function getReader()
1919
{
20-
return $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
20+
return $this->getMockBuilder(\Doctrine\Common\Annotations\Reader::class)
2121
->disableOriginalConstructor()
2222
->getMock()
2323
;
2424
}
2525

2626
public function getClassLoader($reader)
2727
{
28-
return $this->getMockBuilder('Symfony\Component\Routing\Loader\AnnotationClassLoader')
28+
return $this->getMockBuilder(\Symfony\Component\Routing\Loader\AnnotationClassLoader::class)
2929
->setConstructorArgs([$reader])
3030
->getMockForAbstractClass()
3131
;

Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testLoadTraitWithClassConstant()
4444

4545
public function testLoadFileWithoutStartTag()
4646
{
47-
$this->expectException('InvalidArgumentException');
47+
$this->expectException(\InvalidArgumentException::class);
4848
$this->expectExceptionMessage('Did you forgot to add the "<?php" start tag at the beginning of the file?');
4949
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
5050
}

Tests/Loader/ObjectLoaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testLoadCallsServiceAndReturnsCollection()
4545
*/
4646
public function testExceptionWithoutSyntax(string $resourceString)
4747
{
48-
$this->expectException('InvalidArgumentException');
48+
$this->expectException(\InvalidArgumentException::class);
4949
$loader = new TestObjectLoader();
5050
$loader->load($resourceString);
5151
}
@@ -72,16 +72,16 @@ public function testExceptionOnNoObjectReturned()
7272

7373
public function testExceptionOnBadMethod()
7474
{
75-
$this->expectException('BadMethodCallException');
75+
$this->expectException(\BadMethodCallException::class);
7676
$loader = new TestObjectLoader();
7777
$loader->loaderMap = ['my_service' => new \stdClass()];
7878
$loader->load('my_service::method');
7979
}
8080

8181
public function testExceptionOnMethodNotReturningCollection()
8282
{
83-
$this->expectException('LogicException');
84-
$service = $this->getMockBuilder('stdClass')
83+
$this->expectException(\LogicException::class);
84+
$service = $this->getMockBuilder(\stdClass::class)
8585
->setMethods(['loadRoutes'])
8686
->getMock();
8787
$service->expects($this->once())

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PhpFileLoaderTest extends TestCase
2222
{
2323
public function testSupports()
2424
{
25-
$loader = new PhpFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
25+
$loader = new PhpFileLoader($this->getMockBuilder(FileLocator::class)->getMock());
2626

2727
$this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
2828
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class XmlFileLoaderTest extends TestCase
2323
{
2424
public function testSupports()
2525
{
26-
$loader = new XmlFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
26+
$loader = new XmlFileLoader($this->getMockBuilder(FileLocator::class)->getMock());
2727

2828
$this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
2929
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
@@ -38,7 +38,7 @@ public function testLoadWithRoute()
3838
$routeCollection = $loader->load('validpattern.xml');
3939
$route = $routeCollection->get('blog_show');
4040

41-
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
41+
$this->assertInstanceOf(Route::class, $route);
4242
$this->assertSame('/blog/{slug}', $route->getPath());
4343
$this->assertSame('{locale}.example.com', $route->getHost());
4444
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
@@ -215,7 +215,7 @@ public function testLocalizedImportsOfNotLocalizedRoutes()
215215
*/
216216
public function testLoadThrowsExceptionWithInvalidFile($filePath)
217217
{
218-
$this->expectException('InvalidArgumentException');
218+
$this->expectException(\InvalidArgumentException::class);
219219
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
220220
$loader->load($filePath);
221221
}
@@ -225,7 +225,7 @@ public function testLoadThrowsExceptionWithInvalidFile($filePath)
225225
*/
226226
public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation($filePath)
227227
{
228-
$this->expectException('InvalidArgumentException');
228+
$this->expectException(\InvalidArgumentException::class);
229229
$loader = new CustomXmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
230230
$loader->load($filePath);
231231
}
@@ -237,7 +237,7 @@ public function getPathsToInvalidFiles()
237237

238238
public function testDocTypeIsNotAllowed()
239239
{
240-
$this->expectException('InvalidArgumentException');
240+
$this->expectException(\InvalidArgumentException::class);
241241
$this->expectExceptionMessage('Document types are not allowed.');
242242
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
243243
$loader->load('withdoctype.xml');
@@ -445,7 +445,7 @@ public function testLoadRouteWithControllerSetInDefaults()
445445

446446
public function testOverrideControllerInDefaults()
447447
{
448-
$this->expectException('InvalidArgumentException');
448+
$this->expectException(\InvalidArgumentException::class);
449449
$this->expectExceptionMessageMatches('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for "app_blog"/');
450450
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
451451
$loader->load('override_defaults.xml');
@@ -477,7 +477,7 @@ public function provideFilesImportingRoutesWithControllers()
477477

478478
public function testImportWithOverriddenController()
479479
{
480-
$this->expectException('InvalidArgumentException');
480+
$this->expectException(\InvalidArgumentException::class);
481481
$this->expectExceptionMessageMatches('/The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for the "import" tag/');
482482
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
483483
$loader->load('import_override_defaults.xml');

0 commit comments

Comments
 (0)