public function testLoadEventIsTriggered() { $this->idGeneratorMock->shouldReceive('generate')->andReturn('foo-bar'); $self = $this; $this->cacheService->getEventManager()->attach(CacheEvent::EVENT_LOAD, function ($e) use($self) { $self->assertInstanceOf('StrokerCache\\Event\\CacheEvent', $e); $self->assertEquals('foo-bar', $e->getCacheKey()); }); $this->storageMock->shouldReceive('hasItem')->andReturn(true); $this->cacheService->load(); }
/** * @param CacheService $cacheService * @param ModuleOptions $options * @param ServiceLocatorInterface $serviceLocator */ protected function attachStrategiesToEventManager(CacheService $cacheService, ModuleOptions $options, ServiceLocatorInterface $serviceLocator) { // Register enabled strategies on the cacheListener $strategies = $options->getStrategies(); if (isset($strategies['enabled'])) { /** @var $strategyPluginManager \StrokerCache\Strategy\CacheStrategyPluginManager */ $strategyPluginManager = $serviceLocator->get('StrokerCache\\Strategy\\CacheStrategyPluginManager'); foreach ($strategies['enabled'] as $alias => $options) { if (is_numeric($alias)) { $alias = $options; } $strategy = $strategyPluginManager->get($alias, $options); if ($strategy instanceof ListenerAggregateInterface) { $listener = $strategy; } else { $listener = new ShouldCacheStrategyListener($strategy); } $cacheService->getEventManager()->attach($listener); } } }