public function testReadMetadataFromCache()
 {
     $loader = $this->getMock('Symfony\\Component\\Validator\\Mapping\\Loader\\LoaderInterface');
     $cache = $this->getMock('Symfony\\Component\\Validator\\Mapping\\Cache\\CacheInterface');
     $factory = new LazyLoadingMetadataFactory($loader, $cache);
     $metadata = new ClassMetadata(self::PARENT_CLASS);
     $metadata->addConstraint(new ConstraintA());
     $loader->expects($this->never())->method('loadClassMetadata');
     $cache->expects($this->never())->method('has');
     $cache->expects($this->once())->method('read')->will($this->returnValue($metadata));
     $this->assertEquals($metadata, $factory->getMetadataFor(self::PARENT_CLASS));
 }
Example #2
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();
 }
Example #3
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();
 }