5
5
use Driebit \HttpCacheBundle \EventListener \InvalidationListener ;
6
6
use Driebit \HttpCacheBundle \Invalidator \Invalidator ;
7
7
use Driebit \HttpCacheBundle \Invalidator \InvalidatorCollection ;
8
- use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
9
8
use Symfony \Component \HttpFoundation \Request ;
10
9
use Symfony \Component \HttpFoundation \Response ;
11
10
use Symfony \Component \HttpKernel \Event \PostResponseEvent ;
12
11
use \Mockery ;
13
- use Driebit \HttpCacheBundle \HttpCache \Varnish ;
14
12
use Symfony \Component \Routing \Route ;
15
13
use Symfony \Component \Routing \RouteCollection ;
16
14
17
15
class InvalidationListenerTest extends \PHPUnit_Framework_TestCase
18
16
{
19
- public function testNoRoutesInvalidedWhenResponseIsUnsuccessful ()
17
+ public function testNoRoutesInvalidatedWhenResponseIsUnsuccessful ()
20
18
{
21
19
$ cacheManager = \Mockery::mock ('\Driebit\HttpCacheBundle\CacheManager ' )
22
20
->shouldDeferMissing ()
@@ -46,25 +44,27 @@ public function testNoRoutesInvalidedWhenResponseIsUnsuccessful()
46
44
47
45
public function testOnKernelTerminate ()
48
46
{
49
- $ cacheManager = \Mockery::mock ('\Driebit\HttpCacheBundle\CacheManager ' )
50
- ->shouldReceive ('invalidateRoute ' )
51
- ->with ('route_invalidated ' , array ('id ' => '123 ' ))
52
- ->shouldReceive ('invalidateRoute ' )->with ('route_invalidated_special ' , array ('id ' => '123 ' , 'special ' => 'bla ' ))
47
+ $ cacheManager = \Mockery::mock ('\Driebit\HttpCacheBundle\CacheManager ' );
48
+ $ cacheManager ->shouldReceive ('invalidatePath ' )->with ('/retrieve/something/123 ' )
49
+ ->shouldReceive ('invalidatePath ' )->with ('/retrieve/something/123/bla ' )
53
50
->shouldReceive ('flush ' )->once ()
54
51
->getMock ();
55
52
56
53
$ routes = new RouteCollection ();
57
- $ route = new Route ('/edit/something/{id}/{special} ' );
58
- $ route2 = new Route ('/retrieve/something/{id} ' );
59
- $ route3 = new Route ('/retrieve/something/{id}/{special} ' );
60
- $ routes ->add ('route_invalidator ' , $ route );
61
- $ routes ->add ('route_invalidated ' , $ route2 );
62
- $ routes ->add ('route_invalidated_special ' , $ route3 );
54
+ $ routes ->add ('route_invalidator ' , new Route ('/edit/something/{id}/{special} ' ));
55
+ $ routes ->add ('route_invalidated ' , new Route ('/retrieve/something/{id} ' ));
56
+ $ routes ->add ('route_invalidated_special ' , new Route ('/retrieve/something/{id}/{special} ' ));
63
57
58
+ $ requestParams = array ('id ' => 123 , 'special ' => 'bla ' );
64
59
$ router = \Mockery::mock ('\Symfony\Component\Routing\Router ' )
65
60
->shouldDeferMissing ()
66
- ->shouldReceive ('getRouteCollection ' )
67
- ->andReturn ($ routes )
61
+ ->shouldReceive ('generate ' )
62
+ ->with ('route_invalidated ' , $ requestParams )
63
+ ->andReturn ('/retrieve/something/123?special=bla ' )
64
+
65
+ ->shouldReceive ('generate ' )
66
+ ->with ('route_invalidated_special ' , $ requestParams )
67
+ ->andReturn ('/retrieve/something/123/bla ' )
68
68
->getMock ();
69
69
70
70
$ invalidator = new Invalidator ();
@@ -79,7 +79,7 @@ public function testOnKernelTerminate()
79
79
80
80
$ request = new Request ();
81
81
$ request ->attributes ->set ('_route ' , 'route_invalidator ' );
82
- $ request ->attributes ->set ('_route_params ' , array ( ' id ' => ' 123 ' , ' special ' => ' bla ' ) );
82
+ $ request ->attributes ->set ('_route_params ' , $ requestParams );
83
83
84
84
$ event = $ this ->getEvent ($ request );
85
85
$ listener ->onKernelTerminate ($ event );
0 commit comments