diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php index 6df729b02afe1..049887ba35e8b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php @@ -94,8 +94,8 @@ public function load($resource, $type = null) } if (1 === substr_count($controller, ':')) { - $controller = str_replace(':', '::', $controller); - @trigger_error(sprintf('Referencing controllers with a single colon is deprecated since Symfony 4.1. Use %s instead.', $controller), E_USER_DEPRECATED); + $nonDeprecatedNotation = str_replace(':', '::', $controller); + @trigger_error(sprintf('Referencing controllers with a single colon is deprecated since Symfony 4.1. Use %s instead.', $nonDeprecatedNotation), E_USER_DEPRECATED); } $route->setDefault('_controller', $controller); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php index 407158333d89e..5f08cce0ab860 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/DelegatingLoaderTest.php @@ -5,7 +5,11 @@ use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; use Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader; +use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Loader\LoaderResolver; +use Symfony\Component\Config\Loader\LoaderResolverInterface; +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; class DelegatingLoaderTest extends TestCase { @@ -17,4 +21,48 @@ public function testConstructorApi() new DelegatingLoader($controllerNameParser, new LoaderResolver()); $this->assertTrue(true, '__construct() takes a ControllerNameParser and LoaderResolverInterface respectively as its first and second argument.'); } + + /** + * @group legacy + * @expectedDeprecation Referencing controllers with foo:bar:baz is deprecated since Symfony 4.1. Use some_parsed::controller instead. + * @expectedDeprecation Referencing controllers with a single colon is deprecated since Symfony 4.1. Use foo::baz instead. + */ + public function testLoad() + { + $controllerNameParser = $this->getMockBuilder(ControllerNameParser::class) + ->disableOriginalConstructor() + ->getMock(); + + $controllerNameParser->expects($this->once()) + ->method('parse') + ->with('foo:bar:baz') + ->willReturn('some_parsed::controller'); + + $loaderResolver = $this->getMockBuilder(LoaderResolverInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $loader = $this->getMockBuilder(LoaderInterface::class)->getMock(); + + $loaderResolver->expects($this->once()) + ->method('resolve') + ->willReturn($loader); + + $routeCollection = new RouteCollection(); + $routeCollection->add('foo', new Route('/', array('_controller' => 'foo:bar:baz'))); + $routeCollection->add('bar', new Route('/', array('_controller' => 'foo::baz'))); + $routeCollection->add('baz', new Route('/', array('_controller' => 'foo:baz'))); + + $loader->expects($this->once()) + ->method('load') + ->willReturn($routeCollection); + + $delegatingLoader = new DelegatingLoader($controllerNameParser, $loaderResolver); + + $loadedRouteCollection = $delegatingLoader->load('foo'); + $this->assertCount(3, $loadedRouteCollection); + $this->assertSame('some_parsed::controller', $routeCollection->get('foo')->getDefault('_controller')); + $this->assertSame('foo::baz', $routeCollection->get('bar')->getDefault('_controller')); + $this->assertSame('foo:baz', $routeCollection->get('baz')->getDefault('_controller')); + } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy