protected function setUp() { $this->cache = $this->getMockForAbstractClass('Doctrine\\Common\\Cache\\CacheProvider'); $this->cache->expects($this->any())->method('fetch')->will($this->returnValue(false)); $this->cache->expects($this->any())->method('save'); $this->ownershipMetadataProvider = $this->getMockBuilder('OroB2B\\Bundle\\CustomerBundle\\Owner\\Metadata\\FrontendOwnershipMetadataProvider')->disableOriginalConstructor()->getMock(); $this->managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock(); $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->container->expects($this->any())->method('get')->willReturnMap([['orob2b_customer.owner.frontend_ownership_tree_provider.cache', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->cache], ['orob2b_customer.owner.frontend_ownership_metadata_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->ownershipMetadataProvider], ['doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->managerRegistry], ['oro_security.security_facade', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->securityFacade]]); $this->treeProvider = new FrontendOwnerTreeProvider(); $this->treeProvider->setContainer($this->container); }
protected function setUp() { $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $managerRegistry->expects($this->any())->method('getManagerForClass')->willReturn($this->em); $this->cache = $this->getMockForAbstractClass('Doctrine\\Common\\Cache\\CacheProvider'); $this->cache->expects($this->any())->method('fetch')->will($this->returnValue(false)); $this->cache->expects($this->any())->method('save'); $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock(); $this->container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->container->expects($this->any())->method('get')->will($this->returnValueMap([['oro_security.ownership_tree_provider.cache', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->cache], ['oro_security.owner.ownership_metadata_provider', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, new OwnershipMetadataProviderStub($this, ['user' => 'Oro\\Bundle\\UserBundle\\Entity\\User', 'business_unit' => 'Oro\\Bundle\\OrganizationBundle\\Entity\\BusinessUnit'])], ['doctrine', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $managerRegistry], ['oro_security.security_facade', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->securityFacade]])); $this->treeProvider = new OwnerTreeProvider($this->em, $this->cache); $this->treeProvider->setContainer($this->container); }
public function testWarmUpCacheWithClassName() { $this->configProvider->expects($this->once())->method('hasConfig')->with(self::SOME_CLASS)->willReturn(true); $this->configProvider->expects($this->once())->method('getConfig')->with(self::SOME_CLASS)->willReturn($this->config); $this->cache->expects($this->once())->method('fetch')->with(self::SOME_CLASS)->willReturn(false); $this->cache->expects($this->once())->method('save')->with(self::SOME_CLASS); $this->provider->warmUpCache(self::SOME_CLASS); }
/** * Test load from cache cache */ public function testFullCache() { $node = new Node(); $node->setSubnodes(new ArrayCollection())->setId(1); $menu = new Menu(); $menu->setSubnodes(new ArrayCollection())->addSubnode($node); $this->menuRepository->expects($this->any())->method('findOneBy'); $this->cacheProvider->expects($this->once())->method('fetch')->will($this->returnValue('{"1":{"id":1,"name":null,"url":null,"subnodes":[]}}')); $this->cacheProvider->expects($this->any())->method('save'); /** * Data is required twice to test how many times data is fetched from * cache provider, and to test than both times, returned data is the * same */ $this->assertEquals($this->menuManager->loadMenuByCode('admin'), [1 => ['id' => 1, 'name' => null, 'url' => null, 'subnodes' => []]]); $this->assertEquals($this->menuManager->loadMenuByCode('admin'), [1 => ['id' => 1, 'name' => null, 'url' => null, 'subnodes' => []]]); }
public function testWarmUpCacheFilterConfigsByScope() { $config1 = new Config(new EntityConfigId('ownership', 'AcmeBundle\\Entity\\User')); $config2 = new Config(new EntityConfigId('ownership', 'AcmeBundle\\Entity\\Account')); $this->configProvider->expects($this->once())->method('getConfigs')->willReturn([$config1, $config2]); $this->securityConfigProvider->expects($this->atLeastOnce())->method('hasConfig')->willReturn(true); $securityConfig1 = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface'); $securityConfig1->expects($this->once())->method('get')->with('group_name')->willReturn(''); $securityConfig2 = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface'); $securityConfig2->expects($this->once())->method('get')->with('group_name')->willReturn('commerce'); $this->securityConfigProvider->expects($this->atLeastOnce())->method('getConfig')->will($this->onConsecutiveCalls($securityConfig1, $securityConfig2)); $this->cache->expects($this->once())->method('fetch')->with($this->equalTo('AcmeBundle\\Entity\\Account')); $this->provider->warmUpCache(); }
public function testSaveDeferredAndCommit_SecondSaveFails() { $otherCacheItem = $this->getMock('Psr\\Cache\\CacheItemInterface'); $this->cacheItem->expects($this->once())->method('getExpiration')->willReturn(new \DateTime('now +30 seconds')); $this->cacheItem->expects($this->any())->method('getKey')->willReturn($this->cacheKey); $otherCacheKey = 'cache-key-2'; $otherCacheItem->expects($this->once())->method('getExpiration')->willReturn(new \DateTime('now +30 seconds')); $otherCacheItem->expects($this->any())->method('getKey')->willReturn($otherCacheKey); $cacheItemPool = $this->adapter->saveDeferred($this->cacheItem); $this->assertSame($this->adapter, $cacheItemPool); $cacheItemPool = $this->adapter->saveDeferred($otherCacheItem); $this->assertSame($this->adapter, $cacheItemPool); $this->cacheProvider->expects($this->at(0))->method('save')->willReturn(true); $this->cacheProvider->expects($this->at(1))->method('save')->willReturn(false); $this->assertFalse($this->adapter->commit()); }
public function testGetMetadataUndefinedClassWithCache() { $this->configProvider->expects($this->once())->method('hasConfig')->with($this->equalTo('UndefinedClass'))->will($this->returnValue(false)); $this->configProvider->expects($this->never())->method('getConfig'); $this->cache->expects($this->at(0))->method('fetch')->with($this->equalTo('UndefinedClass'))->will($this->returnValue(false)); $this->cache->expects($this->at(2))->method('fetch')->with($this->equalTo('UndefinedClass'))->will($this->returnValue(true)); $this->cache->expects($this->once())->method('save')->with($this->equalTo('UndefinedClass'), $this->equalTo(true)); $this->entityClassResolver = null; $providerWithCleanLocalCache = clone $this->provider; $metadata = new OwnershipMetadata(); // no cache $this->assertEquals($metadata, $this->provider->getMetadata('UndefinedClass')); // local cache $this->assertEquals($metadata, $this->provider->getMetadata('UndefinedClass')); // cache $this->assertEquals($metadata, $providerWithCleanLocalCache->getMetadata('UndefinedClass')); }