1919use FOS \HttpCache \Exception \UnsupportedProxyOperationException ;
2020use FOS \HttpCache \ProxyClient \Varnish ;
2121use \Mockery ;
22+ use Symfony \Component \EventDispatcher \EventDispatcher ;
2223
2324class CacheInvalidatorTest extends \PHPUnit_Framework_TestCase
2425{
2526 public function testSupportsTrue ()
2627 {
27- $ httpCache = new Varnish (array ('localhost ' ));
28+ $ proxyClient = new Varnish (array ('localhost ' ));
2829
29- $ cacheInvalidator = new CacheInvalidator ($ httpCache );
30+ $ cacheInvalidator = new CacheInvalidator ($ proxyClient );
3031
3132 $ this ->assertTrue ($ cacheInvalidator ->supports (CacheInvalidator::PATH ));
3233 $ this ->assertTrue ($ cacheInvalidator ->supports (CacheInvalidator::REFRESH ));
@@ -35,9 +36,9 @@ public function testSupportsTrue()
3536
3637 public function testSupportsFalse ()
3738 {
38- $ httpCache = \Mockery::mock ('\FOS\HttpCache\ProxyClient\ProxyClientInterface ' );
39+ $ proxyClient = \Mockery::mock ('\FOS\HttpCache\ProxyClient\ProxyClientInterface ' );
3940
40- $ cacheInvalidator = new CacheInvalidator ($ httpCache );
41+ $ cacheInvalidator = new CacheInvalidator ($ proxyClient );
4142
4243 $ this ->assertFalse ($ cacheInvalidator ->supports (CacheInvalidator::PATH ));
4344 $ this ->assertFalse ($ cacheInvalidator ->supports (CacheInvalidator::REFRESH ));
@@ -49,21 +50,21 @@ public function testSupportsFalse()
4950 */
5051 public function testSupportsInvalid ()
5152 {
52- $ httpCache = \Mockery::mock ('\FOS\HttpCache\ProxyClient\ProxyClientInterface ' );
53+ $ proxyClient = \Mockery::mock ('\FOS\HttpCache\ProxyClient\ProxyClientInterface ' );
5354
54- $ cacheInvalidator = new CacheInvalidator ($ httpCache );
55+ $ cacheInvalidator = new CacheInvalidator ($ proxyClient );
5556
5657 $ cacheInvalidator ->supports ('garbage ' );
5758 }
5859
5960 public function testInvalidatePath ()
6061 {
61- $ httpCache = \Mockery::mock ('\FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface ' )
62+ $ purge = \Mockery::mock ('\FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface ' )
6263 ->shouldReceive ('purge ' )->once ()->with ('/my/route ' )
6364 ->shouldReceive ('flush ' )->once ()
6465 ->getMock ();
6566
66- $ cacheInvalidator = new CacheInvalidator ($ httpCache );
67+ $ cacheInvalidator = new CacheInvalidator ($ purge );
6768
6869 $ cacheInvalidator
6970 ->invalidatePath ('/my/route ' )
@@ -74,12 +75,12 @@ public function testInvalidatePath()
7475 public function testRefreshPath ()
7576 {
7677 $ headers = array ('X ' => 'Y ' );
77- $ httpCache = \Mockery::mock ('\FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface ' )
78+ $ refresh = \Mockery::mock ('\FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface ' )
7879 ->shouldReceive ('refresh ' )->once ()->with ('/my/route ' , $ headers )
7980 ->shouldReceive ('flush ' )->never ()
8081 ->getMock ();
8182
82- $ cacheInvalidator = new CacheInvalidator ($ httpCache );
83+ $ cacheInvalidator = new CacheInvalidator ($ refresh );
8384
8485 $ cacheInvalidator
8586 ->refreshPath ('/my/route ' , $ headers )
@@ -142,8 +143,8 @@ public function testInvalidateTagsCustomHeader()
142143
143144 public function testMethodException ()
144145 {
145- $ proxy = \Mockery::mock ('\FOS\HttpCache\ProxyClient\ProxyClientInterface ' );
146- $ cacheInvalidator = new CacheInvalidator ($ proxy );
146+ $ proxyClient = \Mockery::mock ('\FOS\HttpCache\ProxyClient\ProxyClientInterface ' );
147+ $ cacheInvalidator = new CacheInvalidator ($ proxyClient );
147148 try {
148149 $ cacheInvalidator ->invalidatePath ('/ ' );
149150 $ this ->fail ('Expected exception ' );
@@ -187,11 +188,11 @@ public function testProxyClientExceptionsAreLogged()
187188 $ exceptions = new ExceptionCollection ();
188189 $ exceptions ->add ($ unreachableException )->add ($ responseException );
189190
190- $ httpCache = \Mockery::mock ('\FOS\HttpCache\ProxyClient\ProxyClientInterface ' )
191+ $ proxyClient = \Mockery::mock ('\FOS\HttpCache\ProxyClient\ProxyClientInterface ' )
191192 ->shouldReceive ('flush ' )->once ()->andThrow ($ exceptions )
192193 ->getMock ();
193194
194- $ cacheInvalidator = new CacheInvalidator ($ httpCache );
195+ $ cacheInvalidator = new CacheInvalidator ($ proxyClient );
195196
196197 $ logger = \Mockery::mock ('\Psr\Log\LoggerInterface ' )
197198 ->shouldReceive ('log ' )->once ()
@@ -212,4 +213,14 @@ public function testProxyClientExceptionsAreLogged()
212213 ->flush ()
213214 ;
214215 }
216+
217+ public function testEventDispatcher ()
218+ {
219+ $ proxyClient = new Varnish (array ('localhost ' ));
220+
221+ $ cacheInvalidator = new CacheInvalidator ($ proxyClient );
222+ $ eventDispatcher = new EventDispatcher ();
223+ $ cacheInvalidator ->setEventDispatcher ($ eventDispatcher );
224+ $ this ->assertSame ($ eventDispatcher , $ cacheInvalidator ->getEventDispatcher ());
225+ }
215226}
0 commit comments