From 88cf0426056f1d3710632b6729025c9805f963df Mon Sep 17 00:00:00 2001 From: Marcelo Lipienski Date: Thu, 5 Dec 2013 10:34:02 -0200 Subject: [PATCH 1/8] fixed one last indentation left behind --- tests/SlmCacheTest/Listener/CacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SlmCacheTest/Listener/CacheTest.php b/tests/SlmCacheTest/Listener/CacheTest.php index 70cbd37..12fdc8a 100644 --- a/tests/SlmCacheTest/Listener/CacheTest.php +++ b/tests/SlmCacheTest/Listener/CacheTest.php @@ -128,7 +128,7 @@ public function testSuccessfulMatchInvokesCacheRetrieval() $mock = $this->getMock('SlmCache\Listener\Cache', array('fromCache'), array($sl)); $mock->expects($this->once()) - ->method('fromCache'); + ->method('fromCache'); $match = new RouteMatch(array()); $match->setMatchedRouteName('home'); From 113ab4651b1977168fceb148c5b346cc8ae9a7e1 Mon Sep 17 00:00:00 2001 From: Marcelo Lipienski Date: Thu, 5 Dec 2013 10:50:52 -0200 Subject: [PATCH 2/8] ignore phpstorm settings directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea From e0858bb8bc592613b00933b66371a9dbdd52bd15 Mon Sep 17 00:00:00 2001 From: Marcelo Lipienski Date: Thu, 5 Dec 2013 20:57:02 -0200 Subject: [PATCH 3/8] Moved caching logic to CacheService and left event listeners in CacheListener. Tests are now divided as well. --- Module.php | 4 +- config/module.config.php | 10 ++ src/SlmCache/Listener/CacheListener.php | 82 +++++++++++++ .../Cache.php => Service/CacheService.php} | 109 ++++++++---------- .../{CacheTest.php => CacheListenerTest.php} | 102 +--------------- .../SlmCacheTest/Service/CacheServiceTest.php | 105 +++++++++++++++++ 6 files changed, 249 insertions(+), 163 deletions(-) create mode 100644 src/SlmCache/Listener/CacheListener.php rename src/SlmCache/{Listener/Cache.php => Service/CacheService.php} (60%) rename tests/SlmCacheTest/Listener/{CacheTest.php => CacheListenerTest.php} (51%) create mode 100644 tests/SlmCacheTest/Service/CacheServiceTest.php diff --git a/Module.php b/Module.php index 9ad0510..fdd254a 100644 --- a/Module.php +++ b/Module.php @@ -70,7 +70,7 @@ public function onBootstrap(EventInterface $e) $em = $app->getEventManager(); $sm = $app->getServiceManager(); - $listener = new Listener\Cache($sm); - $listener->attach($em); + $listener = $sm->get('SlmCache\Listener\CacheListener'); + $em->attach($listener); } } \ No newline at end of file diff --git a/config/module.config.php b/config/module.config.php index 8d02e50..78682b8 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,9 +1,19 @@ array( 'cache' => null, 'routes' => array( ), ), + + 'service_manager' => array( + 'factories' => array( + 'CacheService' => function($sm) { + return new SlmCache\Service\CacheService($sm); + } + ), + ) ); \ No newline at end of file diff --git a/src/SlmCache/Listener/CacheListener.php b/src/SlmCache/Listener/CacheListener.php new file mode 100644 index 0000000..31dd350 --- /dev/null +++ b/src/SlmCache/Listener/CacheListener.php @@ -0,0 +1,82 @@ + + * @copyright 2013 Jurian Sluiman. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @link http://juriansluiman.nl + */ + +namespace SlmCache\Listener; + +use SlmCache\Service\CacheService; + +use Zend\EventManager\AbstractListenerAggregate; +use Zend\EventManager\EventManagerInterface; +use Zend\Mvc\MvcEvent; +use Zend\Mvc\Router\RouteMatch; +use Zend\Http\Response; +use Zend\ServiceManager\ServiceLocatorInterface; +use Zend\Cache\StorageFactory; +use Zend\Cache\Storage\StorageInterface; + +class CacheListener extends AbstractListenerAggregate +{ + protected $cacheService; + + public function __construct(ServiceLocatorInterface $sl) + { + $this->cacheService = new CacheService($sl); + } + + /** + * {@inheritDoc} + */ + public function attach(EventManagerInterface $events) + { + $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRoute')); + $events->attach(MvcEvent::EVENT_FINISH, array($this, 'onFinish')); + } + + public function onRoute(MvcEvent $e) + { + $this->cacheService->matchRoute($e); + } + + public function onFinish(MvcEvent $e) + { + $this->cacheService->saveRoute($e); + } + +} diff --git a/src/SlmCache/Listener/Cache.php b/src/SlmCache/Service/CacheService.php similarity index 60% rename from src/SlmCache/Listener/Cache.php rename to src/SlmCache/Service/CacheService.php index 031e25a..63ed142 100644 --- a/src/SlmCache/Listener/Cache.php +++ b/src/SlmCache/Service/CacheService.php @@ -1,84 +1,45 @@ - * @copyright 2013 Jurian Sluiman. - * @license http://www.opensource.org/licenses/bsd-license.php BSD License - * @link http://juriansluiman.nl - */ - -namespace SlmCache\Listener; - -use Zend\EventManager\AbstractListenerAggregate; -use Zend\EventManager\EventManagerInterface; + +namespace SlmCache\Service; + +use Zend\ServiceManager\ServiceLocatorInterface; +use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\Mvc\MvcEvent; use Zend\Mvc\Router\RouteMatch; -use Zend\Http\Response; -use Zend\ServiceManager\ServiceLocatorInterface; -use Zend\Cache\StorageFactory; -use Zend\Cache\Storage\StorageInterface; -class Cache extends AbstractListenerAggregate +class CacheService implements ServiceLocatorAwareInterface { - protected $cache_prefix = 'slm_cache_'; - protected $match; protected $serviceLocator; - public function __construct(ServiceLocatorInterface $sl) - { - $this->serviceLocator = $sl; + protected $config = array(); + + protected $match; - $config = $sl->get('Config'); + public function __construct(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; - if (isset($config['slm_cache']['cache_prefix'])) { - $this->cache_prefix = $config['slm_cache']['cache_prefix']; - } + $this->configSetup(); } - /** - * {@inheritDoc} - */ - public function attach(EventManagerInterface $events) + protected function configSetup() { - $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'matchRoute')); - $events->attach(MvcEvent::EVENT_FINISH, array($this, 'saveRoute')); + $config = $this->serviceLocator->get('Config'); + + if (!isset($config['slm_cache']['cache_prefix'])) { + $config['slm_cache']['cache_prefix'] = 'slm_cache_'; + } + + // TODO: implement config validation?! + + $this->config = $config; } public function matchRoute(MvcEvent $e) { $match = $this->match($e); + if (null === $match) { return; } @@ -201,4 +162,24 @@ protected function getCache(MvcEvent $e) return $cache; } -} + /** + * Set service locator + * + * @param ServiceLocatorInterface $serviceLocator + */ + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + } + + /** + * Get service locator + * + * @return ServiceLocatorInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } + +} \ No newline at end of file diff --git a/tests/SlmCacheTest/Listener/CacheTest.php b/tests/SlmCacheTest/Listener/CacheListenerTest.php similarity index 51% rename from tests/SlmCacheTest/Listener/CacheTest.php rename to tests/SlmCacheTest/Listener/CacheListenerTest.php index 12fdc8a..cd539db 100644 --- a/tests/SlmCacheTest/Listener/CacheTest.php +++ b/tests/SlmCacheTest/Listener/CacheListenerTest.php @@ -49,16 +49,16 @@ use Zend\Mvc\MvcEvent; use Zend\Mvc\Router\RouteMatch; -class CacheTest extends TestCase +class CacheListenerTest extends TestCase { public function testMatchRouteIsTriggered() { $sl = new ServiceManager; $sl->setService('Config', array()); - $mock = $this->getMock('SlmCache\Listener\Cache', array('matchRoute'), array($sl)); + $mock = $this->getMock('SlmCache\Listener\CacheListener', array('onRoute'), array($sl)); $mock->expects($this->once()) - ->method('matchRoute'); + ->method('onRoute'); $em = new EventManager; $mock->attach($em); @@ -73,9 +73,9 @@ public function testSaveRouteIsTriggered() $sl = new ServiceManager; $sl->setService('Config', array()); - $mock = $this->getMock('SlmCache\Listener\Cache', array('saveRoute'), array($sl)); + $mock = $this->getMock('SlmCache\Listener\CacheListener', array('onFinish'), array($sl)); $mock->expects($this->once()) - ->method('saveRoute'); + ->method('onFinish'); $em = new EventManager; $mock->attach($em); @@ -84,96 +84,4 @@ public function testSaveRouteIsTriggered() $event->setName(MvcEvent::EVENT_FINISH); $em->trigger($event); } - - public function testMatchReturnsNullForMissingRouteMatch() - { - $sl = new ServiceManager; - $sl->setService('Config', array()); - - $listener = new CacheListener($sl); - - $event = new MvcEvent; - $result = $listener->matchRoute($event); - - $this->assertNull($result); - } - - public function testMatchReturnsNullForMissingKey() - { - $sl = new ServiceManager; - $sl->setService('Config', array( - 'slm_cache' => array( - 'routes' => array() - ), - )); - $listener = new CacheListener($sl); - - $event = new MvcEvent; - $event->setRouteMatch(new RouteMatch(array())); - $result = $listener->matchRoute($event); - - $this->assertNull($result); - } - - public function testSuccessfulMatchInvokesCacheRetrieval() - { - $sl = new ServiceManager; - $sl->setService('Config', array( - 'slm_cache' => array( - 'routes' => array( - 'home' => array() - ), - ), - )); - - $mock = $this->getMock('SlmCache\Listener\Cache', array('fromCache'), array($sl)); - $mock->expects($this->once()) - ->method('fromCache'); - - $match = new RouteMatch(array()); - $match->setMatchedRouteName('home'); - - $event = new MvcEvent; - $event->setRouteMatch($match); - - $mock->matchRoute($event); - } - - public function testCachePrefixIsUserDefined() - { - $config = array( - 'slm_cache' => array( - 'cache_prefix' => 'my_cache_prefix' - ) - ); - - $sl = new ServiceManager; - $sl->setService('Config', $config); - - $listener = new CacheListener($sl); - - $this->assertEquals( - $config['slm_cache']['cache_prefix'], - PHPUnit_Framework_Assert::readAttribute($listener, 'cache_prefix') - ); - } - - public function testCachePrefixIsDefault() - { - $config = array( - 'slm_cache' => array( - 'cache' => array(), - ) - ); - - $sl = new ServiceManager; - $sl->setService('Config', $config); - - $listener = new CacheListener($sl); - - $this->assertEquals( - 'slm_cache_', - PHPUnit_Framework_Assert::readAttribute($listener, 'cache_prefix') - ); - } } \ No newline at end of file diff --git a/tests/SlmCacheTest/Service/CacheServiceTest.php b/tests/SlmCacheTest/Service/CacheServiceTest.php new file mode 100644 index 0000000..fe1ca1d --- /dev/null +++ b/tests/SlmCacheTest/Service/CacheServiceTest.php @@ -0,0 +1,105 @@ + array()); + + $sl = new ServiceManager; + $sl->setService('Config', $config); + + $cacheService = new CacheService($sl); + + $generatedConfig = Assert::readAttribute($cacheService, 'config'); + + $this->assertArrayHasKey('cache_prefix', $generatedConfig['slm_cache']); + $this->assertEquals('slm_cache_', $generatedConfig['slm_cache']['cache_prefix']); + } + + public function testUserDefinedCachePrefix() + { + $config = array( + 'slm_cache' => array( + 'cache_prefix' => 'my_cache_prefix_' + ), + ); + + $sl = new ServiceManager; + $sl->setService('Config', $config); + + $cacheService = new CacheService($sl); + + $generatedConfig = Assert::readAttribute($cacheService, 'config'); + + $this->assertArrayHasKey('cache_prefix', $generatedConfig['slm_cache']); + $this->assertEquals($config['slm_cache']['cache_prefix'], $generatedConfig['slm_cache']['cache_prefix']); + } + + public function testMatchReturnsNullForMissingRouteMatch() + { + $sl = new ServiceManager; + $sl->setService('Config', array()); + + $cacheService = new CacheService($sl); + + $event = new MvcEvent; + $result = $cacheService->matchRoute($event); + + $this->assertNull($result); + } + + public function testMatchReturnsNullForMissingKey() + { + $sl = new ServiceManager; + $sl->setService('Config', array( + 'slm_cache' => array( + 'routes' => array() + ), + )); + $cacheService = new CacheService($sl); + + $event = new MvcEvent; + $event->setRouteMatch(new RouteMatch(array())); + $result = $cacheService->matchRoute($event); + + $this->assertNull($result); + } + + public function testSuccessfulMatchInvokesCacheRetrieval() + { + $sl = new ServiceManager; + $sl->setService('Config', array( + 'slm_cache' => array( + 'routes' => array( + 'home' => array() + ), + ), + )); + + $mock = $this->getMock('SlmCache\Service\CacheService', array('fromCache'), array($sl)); + $mock->expects($this->once()) + ->method('fromCache'); + + $match = new RouteMatch(array()); + $match->setMatchedRouteName('home'); + + $event = new MvcEvent; + $event->setRouteMatch($match); + + $mock->matchRoute($event); + } + +} \ No newline at end of file From 599baf6439695f9835727ed9a64e7da8d65aaae4 Mon Sep 17 00:00:00 2001 From: Marcelo Lipienski Date: Fri, 6 Dec 2013 10:19:55 -0200 Subject: [PATCH 4/8] Added CacheFactory and updated module.config to rely upon the factory instead of a closure --- config/module.config.php | 4 +-- src/SlmCache/Factory/CacheFactory.php | 23 ++++++++++++++++ .../SlmCacheTest/Factory/CacheFactoryTest.php | 27 +++++++++++++++++++ .../Listener/CacheListenerTest.php | 3 +-- 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/SlmCache/Factory/CacheFactory.php create mode 100644 tests/SlmCacheTest/Factory/CacheFactoryTest.php diff --git a/config/module.config.php b/config/module.config.php index 78682b8..e01aa3e 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -11,9 +11,7 @@ 'service_manager' => array( 'factories' => array( - 'CacheService' => function($sm) { - return new SlmCache\Service\CacheService($sm); - } + 'CacheService' => 'SlmCache\Factory\CacheFactory' ), ) ); \ No newline at end of file diff --git a/src/SlmCache/Factory/CacheFactory.php b/src/SlmCache/Factory/CacheFactory.php new file mode 100644 index 0000000..d321833 --- /dev/null +++ b/src/SlmCache/Factory/CacheFactory.php @@ -0,0 +1,23 @@ +setService('Config', array()); + + $mock = $this->getMock('SlmCache\Factory\CacheFactory', array('createService')); + $mock->expects($this->once()) + ->method('createService') + ->with($this->equalTo($sl)) + ->will($this->returnValue(new CacheService($sl))); + + $this->assertInstanceOf('SlmCache\Service\CacheService', $mock->createService($sl)); + } +} \ No newline at end of file diff --git a/tests/SlmCacheTest/Listener/CacheListenerTest.php b/tests/SlmCacheTest/Listener/CacheListenerTest.php index cd539db..bda6f32 100644 --- a/tests/SlmCacheTest/Listener/CacheListenerTest.php +++ b/tests/SlmCacheTest/Listener/CacheListenerTest.php @@ -40,9 +40,8 @@ namespace SlmCacheTest\Listener; use PHPUnit_Framework_TestCase as TestCase; -use PHPUnit_Framework_Assert; -use SlmCache\Listener\Cache as CacheListener; +use SlmCache\Listener\CacheListener; use Zend\EventManager\EventManager; use Zend\ServiceManager\ServiceManager; From 0e8e383778236f7de06bc16606af57ced41c75b0 Mon Sep 17 00:00:00 2001 From: Marcelo Lipienski Date: Fri, 6 Dec 2013 11:48:13 -0200 Subject: [PATCH 5/8] Added ListenerFactory and passing tests --- Module.php | 3 +- config/module.config.php | 5 ++-- src/SlmCache/Factory/ListenerFactory.php | 23 ++++++++++++++ .../{CacheFactory.php => ServiceFactory.php} | 2 +- src/SlmCache/Listener/CacheListener.php | 12 +++----- src/SlmCache/Service/CacheService.php | 3 ++ .../Factory/ListenerFactoryTest.php | 30 +++++++++++++++++++ ...FactoryTest.php => ServiceFactoryTest.php} | 4 +-- .../Listener/CacheListenerTest.php | 9 ++++-- 9 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 src/SlmCache/Factory/ListenerFactory.php rename src/SlmCache/Factory/{CacheFactory.php => ServiceFactory.php} (89%) create mode 100644 tests/SlmCacheTest/Factory/ListenerFactoryTest.php rename tests/SlmCacheTest/Factory/{CacheFactoryTest.php => ServiceFactoryTest.php} (82%) diff --git a/Module.php b/Module.php index fdd254a..6c9363b 100644 --- a/Module.php +++ b/Module.php @@ -70,7 +70,8 @@ public function onBootstrap(EventInterface $e) $em = $app->getEventManager(); $sm = $app->getServiceManager(); - $listener = $sm->get('SlmCache\Listener\CacheListener'); + $listener = $sm->get('CacheListener'); + $em->attach($listener); } } \ No newline at end of file diff --git a/config/module.config.php b/config/module.config.php index e01aa3e..0bcd211 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -11,7 +11,8 @@ 'service_manager' => array( 'factories' => array( - 'CacheService' => 'SlmCache\Factory\CacheFactory' + 'CacheService' => 'SlmCache\Factory\ServiceFactory', + 'CacheListener' => 'SlmCache\Factory\ListenerFactory', ), - ) + ), ); \ No newline at end of file diff --git a/src/SlmCache/Factory/ListenerFactory.php b/src/SlmCache/Factory/ListenerFactory.php new file mode 100644 index 0000000..b00a4ca --- /dev/null +++ b/src/SlmCache/Factory/ListenerFactory.php @@ -0,0 +1,23 @@ +get('CacheService')); + } + +} \ No newline at end of file diff --git a/src/SlmCache/Factory/CacheFactory.php b/src/SlmCache/Factory/ServiceFactory.php similarity index 89% rename from src/SlmCache/Factory/CacheFactory.php rename to src/SlmCache/Factory/ServiceFactory.php index d321833..07a83db 100644 --- a/src/SlmCache/Factory/CacheFactory.php +++ b/src/SlmCache/Factory/ServiceFactory.php @@ -7,7 +7,7 @@ use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -class CacheFactory implements FactoryInterface +class ServiceFactory implements FactoryInterface { /** * Create service diff --git a/src/SlmCache/Listener/CacheListener.php b/src/SlmCache/Listener/CacheListener.php index 31dd350..6adc807 100644 --- a/src/SlmCache/Listener/CacheListener.php +++ b/src/SlmCache/Listener/CacheListener.php @@ -45,19 +45,15 @@ use Zend\EventManager\AbstractListenerAggregate; use Zend\EventManager\EventManagerInterface; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Router\RouteMatch; -use Zend\Http\Response; use Zend\ServiceManager\ServiceLocatorInterface; -use Zend\Cache\StorageFactory; -use Zend\Cache\Storage\StorageInterface; class CacheListener extends AbstractListenerAggregate { protected $cacheService; - public function __construct(ServiceLocatorInterface $sl) + public function __construct(CacheService $cacheService) { - $this->cacheService = new CacheService($sl); + $this->cacheService = $cacheService; } /** @@ -65,8 +61,8 @@ public function __construct(ServiceLocatorInterface $sl) */ public function attach(EventManagerInterface $events) { - $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRoute')); - $events->attach(MvcEvent::EVENT_FINISH, array($this, 'onFinish')); + $events->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRoute'), -100); + $events->attach(MvcEvent::EVENT_FINISH, array($this, 'onFinish'), 100); } public function onRoute(MvcEvent $e) diff --git a/src/SlmCache/Service/CacheService.php b/src/SlmCache/Service/CacheService.php index 63ed142..4658e02 100644 --- a/src/SlmCache/Service/CacheService.php +++ b/src/SlmCache/Service/CacheService.php @@ -6,6 +6,8 @@ use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\Mvc\MvcEvent; use Zend\Mvc\Router\RouteMatch; +use Zend\Cache\StorageFactory; +use Zend\Cache\Storage\StorageInterface; class CacheService implements ServiceLocatorAwareInterface { @@ -73,6 +75,7 @@ protected function match(MvcEvent $e) } $route = $match->getMatchedRouteName(); + $config = $this->serviceLocator->get('Config'); $routes = $config['slm_cache']['routes']; diff --git a/tests/SlmCacheTest/Factory/ListenerFactoryTest.php b/tests/SlmCacheTest/Factory/ListenerFactoryTest.php new file mode 100644 index 0000000..859487f --- /dev/null +++ b/tests/SlmCacheTest/Factory/ListenerFactoryTest.php @@ -0,0 +1,30 @@ +setService('Config', array()); + + $cacheService = new CacheService($sl); + + $mock = $this->getMock('SlmCache\Factory\ListenerFactory', array('createService')); + $mock->expects($this->once()) + ->method('createService') + ->with($this->equalTo($sl)) + ->will($this->returnValue(new CacheListener($cacheService))); + + $this->assertInstanceOf('SlmCache\Listener\CacheListener', $mock->createService($sl)); + } +} \ No newline at end of file diff --git a/tests/SlmCacheTest/Factory/CacheFactoryTest.php b/tests/SlmCacheTest/Factory/ServiceFactoryTest.php similarity index 82% rename from tests/SlmCacheTest/Factory/CacheFactoryTest.php rename to tests/SlmCacheTest/Factory/ServiceFactoryTest.php index b769e12..a41e057 100644 --- a/tests/SlmCacheTest/Factory/CacheFactoryTest.php +++ b/tests/SlmCacheTest/Factory/ServiceFactoryTest.php @@ -9,14 +9,14 @@ use Zend\ServiceManager\ServiceManager; -class CacheFactoryTest extends TestCase +class ServiceFactoryTest extends TestCase { public function testSuccessfullyCreateService() { $sl = new ServiceManager; $sl->setService('Config', array()); - $mock = $this->getMock('SlmCache\Factory\CacheFactory', array('createService')); + $mock = $this->getMock('SlmCache\Factory\ServiceFactory', array('createService')); $mock->expects($this->once()) ->method('createService') ->with($this->equalTo($sl)) diff --git a/tests/SlmCacheTest/Listener/CacheListenerTest.php b/tests/SlmCacheTest/Listener/CacheListenerTest.php index bda6f32..8bb0597 100644 --- a/tests/SlmCacheTest/Listener/CacheListenerTest.php +++ b/tests/SlmCacheTest/Listener/CacheListenerTest.php @@ -42,6 +42,7 @@ use PHPUnit_Framework_TestCase as TestCase; use SlmCache\Listener\CacheListener; +use SlmCache\Service\CacheService; use Zend\EventManager\EventManager; use Zend\ServiceManager\ServiceManager; @@ -55,7 +56,9 @@ public function testMatchRouteIsTriggered() $sl = new ServiceManager; $sl->setService('Config', array()); - $mock = $this->getMock('SlmCache\Listener\CacheListener', array('onRoute'), array($sl)); + $cacheService = new CacheService($sl); + + $mock = $this->getMock('SlmCache\Listener\CacheListener', array('onRoute'), array($cacheService)); $mock->expects($this->once()) ->method('onRoute'); @@ -72,7 +75,9 @@ public function testSaveRouteIsTriggered() $sl = new ServiceManager; $sl->setService('Config', array()); - $mock = $this->getMock('SlmCache\Listener\CacheListener', array('onFinish'), array($sl)); + $cacheService = new CacheService($sl); + + $mock = $this->getMock('SlmCache\Listener\CacheListener', array('onFinish'), array($cacheService)); $mock->expects($this->once()) ->method('onFinish'); From d4c0dc13a51a94b07fee25aafc58965414e3002c Mon Sep 17 00:00:00 2001 From: Marcelo Lipienski Date: Fri, 6 Dec 2013 11:55:09 -0200 Subject: [PATCH 6/8] Removed new lines I mistakenly added, so now code matches original one --- src/SlmCache/Service/CacheService.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/SlmCache/Service/CacheService.php b/src/SlmCache/Service/CacheService.php index 4658e02..97f7a55 100644 --- a/src/SlmCache/Service/CacheService.php +++ b/src/SlmCache/Service/CacheService.php @@ -41,7 +41,6 @@ protected function configSetup() public function matchRoute(MvcEvent $e) { $match = $this->match($e); - if (null === $match) { return; } @@ -75,7 +74,6 @@ protected function match(MvcEvent $e) } $route = $match->getMatchedRouteName(); - $config = $this->serviceLocator->get('Config'); $routes = $config['slm_cache']['routes']; From 2e0b3559f8b0500ddceadda6e37bddc9665912a2 Mon Sep 17 00:00:00 2001 From: Marcelo Lipienski Date: Fri, 6 Dec 2013 12:56:17 -0200 Subject: [PATCH 7/8] removed my personal .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 485dee6..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.idea From 84397b1a79cde69f7d43e7fe79b1c39a7be72c9b Mon Sep 17 00:00:00 2001 From: Marcelo Lipienski Date: Fri, 6 Dec 2013 13:17:34 -0200 Subject: [PATCH 8/8] added copyright information --- src/SlmCache/Service/CacheService.php | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/SlmCache/Service/CacheService.php b/src/SlmCache/Service/CacheService.php index 97f7a55..31688e0 100644 --- a/src/SlmCache/Service/CacheService.php +++ b/src/SlmCache/Service/CacheService.php @@ -1,4 +1,42 @@ + * @copyright 2013 Jurian Sluiman. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @link http://juriansluiman.nl + */ namespace SlmCache\Service;