예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
     $annotatedClassPatterns = $cacheDir . '/annotations.map';
     if (!is_file($annotatedClassPatterns)) {
         $adapter->warmUp(array());
         return;
     }
     $annotatedClasses = (include $annotatedClassPatterns);
     $arrayPool = new ArrayAdapter(0, false);
     $reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayPool));
     $throwingAutoloader = function ($class) {
         throw new \ReflectionException(sprintf('Class %s does not exist', $class));
     };
     spl_autoload_register($throwingAutoloader);
     try {
         foreach ($annotatedClasses as $class) {
             try {
                 $this->readAllComponents($reader, $class);
             } catch (\ReflectionException $e) {
                 // ignore failing reflection
             }
         }
     } finally {
         spl_autoload_unregister($throwingAutoloader);
     }
     $values = $arrayPool->getValues();
     $adapter->warmUp($values);
     foreach ($values as $k => $v) {
         $item = $this->fallbackPool->getItem($k);
         $this->fallbackPool->saveDeferred($item->set($v));
     }
     $this->fallbackPool->commit();
 }
예제 #2
0
 public function testWarmUpWithoutLoader()
 {
     $validatorBuilder = new ValidatorBuilder();
     $file = sys_get_temp_dir() . '/cache-validator-without-loaders.php';
     @unlink($file);
     $fallbackPool = new ArrayAdapter();
     $warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
     $warmer->warmUp(dirname($file));
     $this->assertFileExists($file);
     $values = (require $file);
     $this->assertInternalType('array', $values);
     $this->assertCount(0, $values);
     $values = $fallbackPool->getValues();
     $this->assertInternalType('array', $values);
     $this->assertCount(0, $values);
 }
예제 #3
0
 public function testWarmUpWithoutLoader()
 {
     if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
         $this->markTestSkipped('The Serializer default cache warmer has been introduced in the Serializer Component version 3.2.');
     }
     $file = sys_get_temp_dir() . '/cache-serializer-without-loader.php';
     @unlink($file);
     $fallbackPool = new ArrayAdapter();
     $warmer = new SerializerCacheWarmer(array(), $file, $fallbackPool);
     $warmer->warmUp(dirname($file));
     $this->assertFileExists($file);
     $values = (require $file);
     $this->assertInternalType('array', $values);
     $this->assertCount(0, $values);
     $values = $fallbackPool->getValues();
     $this->assertInternalType('array', $values);
     $this->assertCount(0, $values);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
         return;
     }
     $adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
     $arrayPool = new ArrayAdapter(0, false);
     $metadataFactory = new CacheClassMetadataFactory(new ClassMetadataFactory(new LoaderChain($this->loaders)), $arrayPool);
     foreach ($this->extractSupportedLoaders($this->loaders) as $loader) {
         foreach ($loader->getMappedClasses() as $mappedClass) {
             $metadataFactory->getMetadataFor($mappedClass);
         }
     }
     $values = $arrayPool->getValues();
     $adapter->warmUp($values);
     foreach ($values as $k => $v) {
         $item = $this->fallbackPool->getItem($k);
         $this->fallbackPool->saveDeferred($item->set($v));
     }
     $this->fallbackPool->commit();
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
     $annotatedClassPatterns = $cacheDir . '/annotations.map';
     if (!is_file($annotatedClassPatterns)) {
         $adapter->warmUp(array());
         return;
     }
     $annotatedClasses = (include $annotatedClassPatterns);
     $arrayPool = new ArrayAdapter(0, false);
     $reader = new CachedReader($this->annotationReader, new DoctrineProvider($arrayPool));
     foreach ($annotatedClasses as $class) {
         $this->readAllComponents($reader, $class);
     }
     $values = $arrayPool->getValues();
     $adapter->warmUp($values);
     foreach ($values as $k => $v) {
         $item = $this->fallbackPool->getItem($k);
         $this->fallbackPool->saveDeferred($item->set($v));
     }
     $this->fallbackPool->commit();
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     if (!method_exists($this->validatorBuilder, 'getLoaders')) {
         return;
     }
     $adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
     $arrayPool = new ArrayAdapter(0, false);
     $loaders = $this->validatorBuilder->getLoaders();
     $metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayPool));
     foreach ($this->extractSupportedLoaders($loaders) as $loader) {
         foreach ($loader->getMappedClasses() as $mappedClass) {
             $metadataFactory->getMetadataFor($mappedClass);
         }
     }
     $values = $arrayPool->getValues();
     $adapter->warmUp($values);
     foreach ($values as $k => $v) {
         $item = $this->fallbackPool->getItem($k);
         $this->fallbackPool->saveDeferred($item->set($v));
     }
     $this->fallbackPool->commit();
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     if (!method_exists($this->validatorBuilder, 'getLoaders')) {
         return;
     }
     $adapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
     $arrayPool = new ArrayAdapter(0, false);
     $loaders = $this->validatorBuilder->getLoaders();
     $metadataFactory = new LazyLoadingMetadataFactory(new LoaderChain($loaders), new Psr6Cache($arrayPool));
     $throwingAutoloader = function ($class) {
         throw new \ReflectionException(sprintf('Class %s does not exist', $class));
     };
     spl_autoload_register($throwingAutoloader);
     try {
         foreach ($this->extractSupportedLoaders($loaders) as $loader) {
             foreach ($loader->getMappedClasses() as $mappedClass) {
                 try {
                     if ($metadataFactory->hasMetadataFor($mappedClass)) {
                         $metadataFactory->getMetadataFor($mappedClass);
                     }
                 } catch (\ReflectionException $e) {
                     // ignore failing reflection
                 }
             }
         }
     } finally {
         spl_autoload_unregister($throwingAutoloader);
     }
     $values = $arrayPool->getValues();
     $adapter->warmUp($values);
     foreach ($values as $k => $v) {
         $item = $this->fallbackPool->getItem($k);
         $this->fallbackPool->saveDeferred($item->set($v));
     }
     $this->fallbackPool->commit();
 }
예제 #8
0
 /**
  * testClearCacheAfterUpdate
  *
  * @access public
  *
  * @return void
  */
 public function testClearCacheAfterUpdate()
 {
     $mapping = new Mapping('/v12');
     $mapping->setMapping([new ClassMetadata('products', 'Mapado\\RestClientSdk\\Tests\\Model\\Product', 'mock\\Mapado\\RestClientSdk\\EntityRepository')]);
     $this->calling($this->mockedSdk)->getMapping = $mapping;
     $this->calling($this->mockedSdk)->getSerializer = new \Mapado\RestClientSdk\Model\Serializer($mapping);
     $product1 = new \Mapado\RestClientSdk\Tests\Model\Product();
     $product2 = new \Mapado\RestClientSdk\Tests\Model\Product();
     $product3 = new \Mapado\RestClientSdk\Tests\Model\Product();
     $product1->setId('/v12/products/1');
     $product2->setId('/v12/products/2');
     $product3->setId('/v12/products/3');
     $this->calling($this->mockedHydrator)->hydrate = $product1;
     $this->calling($this->mockedHydrator)->hydrateList = [$product1, $product2, $product3];
     $arrayAdapter = new ArrayAdapter(0, false);
     $this->calling($this->mockedSdk)->getCacheItemPool = $arrayAdapter;
     $this->calling($this->mockedSdk)->getCachePrefix = 'test_prefix_';
     $this->calling($this->mockedRestClient)->get = $product1;
     $this->calling($this->mockedRestClient)->put = $product1;
     $this->calling($this->mockedRestClient)->delete = null;
     $repository = new \mock\Mapado\RestClientSdk\EntityRepository($this->mockedSdk, $this->mockedRestClient, 'Mapado\\RestClientSdk\\Tests\\Model\\Product');
     $this->if($repository->find(1))->then->boolean($arrayAdapter->hasItem('test_prefix__v12_products_1'))->isTrue()->if($repository->find(1))->then->mock($this->mockedRestClient)->call('get')->withArguments('/v12/products/1')->once()->if($repository->update($product1))->boolean($arrayAdapter->hasItem('test_prefix__v12_products_1'))->isFalse()->if($repository->find(1))->then->mock($this->mockedRestClient)->call('get')->withArguments('/v12/products/1')->twice()->if($repository->remove($product1))->then->boolean($arrayAdapter->hasItem('test_prefix__v12_products_1'))->isFalse();
 }