public function createService(ServiceLocatorInterface $createService) { $countryCache = new Cache(); $countryCache->setServiceManager($createService); $countryCache->setPopulator(new Country()); return $countryCache; }
public function testGettingCacheEntityWithInvalidCache() { $mockConfig = array('phpug' => array('entity' => array('cache' => array('country' => array('cacheLifeTime' => 'P1M'))))); $mockCache = M::mock('\\Phpug\\Entity\\Cache'); $mockCache->shouldReceive('setType')->andReturn($mockCache); $mockCache->shouldReceive('setGroup')->andReturn($mockCache); $mockCache->shouldReceive('add'); $mockCache->shouldReceive('getLastChangeDate')->andReturn((new \DateTime())->sub(new \DateInterval('P1M1D'))); $mockCache->shouldReceive('setCache')->with('foobar'); $mockCache->shouldReceive('setLastChangeDate'); $mockEm = M::mock('stdObject'); $mockEm->shouldReceive('persist')->once(); $mockEm->shouldReceive('flush')->once(); $sm = M::mock('\\Zend\\ServiceManager\\ServiceManager'); $sm->shouldReceive('get')->with('Phpug\\Entity\\Cache')->andReturn($mockCache); $sm->shouldReceive('get')->with('config')->andReturn($mockConfig); $sm->shouldReceive('get')->with('doctrine.entitymanager.orm_default')->andReturn($mockEm); $ug = M::mock('\\Phpug\\Entity\\Usergroup', array('foo'))->shouldReceive('getCaches')->once()->andReturn(array())->mock(); $pe = M::mock('\\Phpug\\Cache\\CachePopulatorInterface'); $pe->shouldReceive('populate')->andReturn('foobar'); $country = new Country(); $country->setUsergroup($ug); $country->setPopulator($pe); $this->assertSame($country, $country->setServiceManager($sm)); $this->assertAttributeSame($sm, 'serviceManager', $country); $this->assertSame($mockCache, $country->getCache()); }