5
5
use PHPUnit \Framework \TestCase ;
6
6
use Symfony \Bundle \FrameworkBundle \Controller \ControllerNameParser ;
7
7
use Symfony \Bundle \FrameworkBundle \Routing \DelegatingLoader ;
8
+ use Symfony \Component \Config \Loader \LoaderInterface ;
8
9
use Symfony \Component \Config \Loader \LoaderResolver ;
10
+ use Symfony \Component \Config \Loader \LoaderResolverInterface ;
11
+ use Symfony \Component \Routing \Route ;
12
+ use Symfony \Component \Routing \RouteCollection ;
9
13
10
14
class DelegatingLoaderTest extends TestCase
11
15
{
@@ -17,4 +21,48 @@ public function testConstructorApi()
17
21
new DelegatingLoader ($ controllerNameParser , new LoaderResolver ());
18
22
$ this ->assertTrue (true , '__construct() takes a ControllerNameParser and LoaderResolverInterface respectively as its first and second argument. ' );
19
23
}
24
+
25
+ /**
26
+ * @group legacy
27
+ * @expectedDeprecation Referencing controllers with foo:bar:baz is deprecated since Symfony 4.1. Use some_parsed::controller instead.
28
+ * @expectedDeprecation Referencing controllers with a single colon is deprecated since Symfony 4.1. Use foo::baz instead.
29
+ */
30
+ public function testLoad ()
31
+ {
32
+ $ controllerNameParser = $ this ->getMockBuilder (ControllerNameParser::class)
33
+ ->disableOriginalConstructor ()
34
+ ->getMock ();
35
+
36
+ $ controllerNameParser ->expects ($ this ->once ())
37
+ ->method ('parse ' )
38
+ ->with ('foo:bar:baz ' )
39
+ ->willReturn ('some_parsed::controller ' );
40
+
41
+ $ loaderResolver = $ this ->getMockBuilder (LoaderResolverInterface::class)
42
+ ->disableOriginalConstructor ()
43
+ ->getMock ();
44
+
45
+ $ loader = $ this ->getMockBuilder (LoaderInterface::class)->getMock ();
46
+
47
+ $ loaderResolver ->expects ($ this ->once ())
48
+ ->method ('resolve ' )
49
+ ->willReturn ($ loader );
50
+
51
+ $ routeCollection = new RouteCollection ();
52
+ $ routeCollection ->add ('foo ' , new Route ('/ ' , array ('_controller ' => 'foo:bar:baz ' )));
53
+ $ routeCollection ->add ('bar ' , new Route ('/ ' , array ('_controller ' => 'foo::baz ' )));
54
+ $ routeCollection ->add ('baz ' , new Route ('/ ' , array ('_controller ' => 'foo:baz ' )));
55
+
56
+ $ loader ->expects ($ this ->once ())
57
+ ->method ('load ' )
58
+ ->willReturn ($ routeCollection );
59
+
60
+ $ delegatingLoader = new DelegatingLoader ($ controllerNameParser , $ loaderResolver );
61
+
62
+ $ loadedRouteCollection = $ delegatingLoader ->load ('foo ' );
63
+ $ this ->assertCount (3 , $ loadedRouteCollection );
64
+ $ this ->assertSame ('some_parsed::controller ' , $ routeCollection ->get ('foo ' )->getDefault ('_controller ' ));
65
+ $ this ->assertSame ('foo::baz ' , $ routeCollection ->get ('bar ' )->getDefault ('_controller ' ));
66
+ $ this ->assertSame ('foo:baz ' , $ routeCollection ->get ('baz ' )->getDefault ('_controller ' ));
67
+ }
20
68
}
0 commit comments