mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-26 13:44:19 +01:00
Package operations: 2 installs, 23 updates, 0 removals - Updating psr/log (1.1.0 => 1.1.2) - Updating symfony/debug (v3.4.30 => v3.4.35) - Updating symfony/console (v3.4.30 => v3.4.35) - Updating symfony/dotenv (v3.4.30 => v3.4.35) - Updating symfony/routing (v3.4.30 => v3.4.35) - Updating symfony/finder (v3.4.30 => v3.4.35) - Updating symfony/filesystem (v3.4.30 => v3.4.35) - Installing symfony/polyfill-util (v1.12.0) - Installing symfony/polyfill-php56 (v1.12.0) - Updating symfony/http-foundation (v3.4.30 => v3.4.35) - Updating symfony/event-dispatcher (v3.4.30 => v3.4.35) - Updating symfony/http-kernel (v3.4.30 => v3.4.35) - Updating symfony/config (v3.4.30 => v3.4.35) - Updating symfony/dependency-injection (v3.4.30 => v3.4.35) - Updating symfony/class-loader (v3.4.30 => v3.4.35) - Updating symfony/cache (v3.4.30 => v3.4.35) - Updating symfony/framework-bundle (v3.4.30 => v3.4.35) - Updating twig/twig (v1.42.2 => v1.42.4) - Updating symfony/twig-bridge (v3.4.30 => v3.4.35) - Updating symfony/twig-bundle (v3.4.30 => v3.4.35) - Updating symfony/yaml (v3.4.30 => v3.4.35) - Updating symfony/stopwatch (v3.4.30 => v3.4.35) - Updating symfony/var-dumper (v3.4.30 => v3.4.35) - Updating symfony/web-profiler-bundle (v3.4.30 => v3.4.35) - Updating symfony/css-selector (v3.4.30 => v3.4.35)
156 lines
5.9 KiB
PHP
156 lines
5.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Tests\CacheWarmer;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\CacheWarmer\ValidatorCacheWarmer;
|
|
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
|
use Symfony\Component\Cache\Adapter\NullAdapter;
|
|
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
|
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|
use Symfony\Component\Validator\ValidatorBuilder;
|
|
|
|
class ValidatorCacheWarmerTest extends TestCase
|
|
{
|
|
public function testWarmUp()
|
|
{
|
|
$validatorBuilder = new ValidatorBuilder();
|
|
$validatorBuilder->addXmlMapping(__DIR__.'/../Fixtures/Validation/Resources/person.xml');
|
|
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/author.yml');
|
|
$validatorBuilder->addMethodMapping('loadValidatorMetadata');
|
|
$validatorBuilder->enableAnnotationMapping();
|
|
|
|
$file = sys_get_temp_dir().'/cache-validator.php';
|
|
@unlink($file);
|
|
|
|
$fallbackPool = new ArrayAdapter();
|
|
|
|
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
|
|
$warmer->warmUp(\dirname($file));
|
|
|
|
$this->assertFileExists($file);
|
|
|
|
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
|
|
|
|
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person')->isHit());
|
|
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author')->isHit());
|
|
|
|
$values = $fallbackPool->getValues();
|
|
|
|
$this->assertIsArray($values);
|
|
$this->assertCount(2, $values);
|
|
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person', $values);
|
|
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author', $values);
|
|
}
|
|
|
|
public function testWarmUpWithAnnotations()
|
|
{
|
|
$validatorBuilder = new ValidatorBuilder();
|
|
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/categories.yml');
|
|
$validatorBuilder->enableAnnotationMapping();
|
|
|
|
$file = sys_get_temp_dir().'/cache-validator-with-annotations.php';
|
|
@unlink($file);
|
|
|
|
$fallbackPool = new ArrayAdapter();
|
|
|
|
$warmer = new ValidatorCacheWarmer($validatorBuilder, $file, $fallbackPool);
|
|
$warmer->warmUp(\dirname($file));
|
|
|
|
$this->assertFileExists($file);
|
|
|
|
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
|
|
|
|
$item = $arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category');
|
|
$this->assertTrue($item->isHit());
|
|
|
|
$this->assertInstanceOf(ClassMetadata::class, $item->get());
|
|
|
|
$values = $fallbackPool->getValues();
|
|
|
|
$this->assertIsArray($values);
|
|
$this->assertCount(2, $values);
|
|
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
|
|
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.SubCategory', $values);
|
|
}
|
|
|
|
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 = $fallbackPool->getValues();
|
|
|
|
$this->assertIsArray($values);
|
|
$this->assertCount(0, $values);
|
|
}
|
|
|
|
/**
|
|
* Test that the cache warming process is not broken if a class loader
|
|
* throws an exception (on class / file not found for example).
|
|
*/
|
|
public function testClassAutoloadException()
|
|
{
|
|
$this->assertFalse(class_exists($mappedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_ValidatorCacheWarmerTest', false));
|
|
|
|
$validatorBuilder = new ValidatorBuilder();
|
|
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/does_not_exist.yaml');
|
|
$warmer = new ValidatorCacheWarmer($validatorBuilder, tempnam(sys_get_temp_dir(), __FUNCTION__), new ArrayAdapter());
|
|
|
|
spl_autoload_register($classloader = function ($class) use ($mappedClass) {
|
|
if ($class === $mappedClass) {
|
|
throw new \DomainException('This exception should be caught by the warmer.');
|
|
}
|
|
}, true, true);
|
|
|
|
$warmer->warmUp('foo');
|
|
|
|
spl_autoload_unregister($classloader);
|
|
}
|
|
|
|
/**
|
|
* Test that the cache warming process is broken if a class loader throws an
|
|
* exception but that is unrelated to the class load.
|
|
*/
|
|
public function testClassAutoloadExceptionWithUnrelatedException()
|
|
{
|
|
$this->expectException(\DomainException::class);
|
|
$this->expectExceptionMessage('This exception should not be caught by the warmer.');
|
|
|
|
$this->assertFalse(class_exists($mappedClass = 'AClassThatDoesNotExist_FWB_CacheWarmer_ValidatorCacheWarmerTest', false));
|
|
|
|
$validatorBuilder = new ValidatorBuilder();
|
|
$validatorBuilder->addYamlMapping(__DIR__.'/../Fixtures/Validation/Resources/does_not_exist.yaml');
|
|
$warmer = new ValidatorCacheWarmer($validatorBuilder, tempnam(sys_get_temp_dir(), __FUNCTION__), new ArrayAdapter());
|
|
|
|
spl_autoload_register($classLoader = function ($class) use ($mappedClass) {
|
|
if ($class === $mappedClass) {
|
|
eval('class '.$mappedClass.'{}');
|
|
throw new \DomainException('This exception should not be caught by the warmer.');
|
|
}
|
|
}, true, true);
|
|
|
|
$warmer->warmUp('foo');
|
|
|
|
spl_autoload_unregister($classLoader);
|
|
}
|
|
}
|