1616
1717use \PHPUnit \Framework \TestCase ;
1818
19- use \BitFrame \Router \RouteGroup ;
19+ use \BitFrame \Router \{ RouteGroup , RouteCollectionInterface } ;
2020
2121/**
2222 * @covers \BitFrame\Router\RouteGroup
@@ -28,7 +28,7 @@ class RouteGroupTest extends TestCase
2828 */
2929 public function testGroupIsInvokedAndAddsRoutesToCollection ()
3030 {
31- $ callback = function () {};
31+ $ callback = function () {};
3232 $ collection = $ this ->createMock ('\BitFrame\Router\RouteCollectionInterface ' );
3333 $ route = $ this ->createMock ('\BitFrame\Router\Route ' );
3434
@@ -86,7 +86,13 @@ public function testGroupIsInvokedAndAddsRoutesToCollection()
8686 ->with ($ this ->equalTo ('HEAD ' ), $ this ->equalTo ('/acme/route ' ), $ this ->equalTo ($ callback ))
8787 ->will ($ this ->returnValue ($ route ));
8888
89- $ group = new RouteGroup ('/acme ' , function ($ route ) use ($ callback ) {
89+ $ phpunit = $ this ;
90+
91+ $ group = new RouteGroup ('/acme ' , function (RouteCollectionInterface $ route ) use ($ callback , $ phpunit ) {
92+ // RouteGroup implements RouteCollectionInterface, so...
93+ $ phpunit ->assertInstanceOf (RouteGroup::class, $ this );
94+ $ phpunit ->assertInstanceOf (RouteCollectionInterface::class, $ this );
95+
9096 $ route ->get ('/route ' , $ callback )->setHost ('example.com ' )->setScheme ('https ' );
9197 $ route ->post ('/route ' , $ callback );
9298 $ route ->put ('/route ' , $ callback );
@@ -98,4 +104,29 @@ public function testGroupIsInvokedAndAddsRoutesToCollection()
98104
99105 $ group ();
100106 }
107+
108+ public function testRouteGroupClassContextIsBoundToRouteGroupCollection ()
109+ {
110+ $ callback = function () {};
111+ $ collection = $ this ->createMock ('\BitFrame\Router\RouteCollectionInterface ' );
112+ $ route = $ this ->createMock ('\BitFrame\Router\Route ' );
113+
114+ $ phpunit = $ this ;
115+
116+ $ group = new RouteGroup ('/acme ' , function () use ($ callback , $ phpunit ) {
117+ // RouteGroup implements RouteCollectionInterface, so...
118+ $ phpunit ->assertInstanceOf (RouteGroup::class, $ this );
119+ $ phpunit ->assertInstanceOf (RouteCollectionInterface::class, $ this );
120+
121+ $ this ->get ('/route ' , $ callback )->setHost ('example.com ' )->setScheme ('https ' );
122+ $ this ->post ('/route ' , $ callback );
123+ $ this ->put ('/route ' , $ callback );
124+ $ this ->patch ('/route ' , $ callback );
125+ $ this ->delete ('/route ' , $ callback );
126+ $ this ->options ('/route ' , $ callback );
127+ $ this ->head ('/route ' , $ callback );
128+ }, $ collection );
129+
130+ $ group ();
131+ }
101132}
0 commit comments