|
16 | 16 | use Symfony\Bundle\FrameworkBundle\Tests\TestCase; |
17 | 17 | use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass; |
18 | 18 | use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; |
| 19 | +use Symfony\Component\Cache\Adapter\AdapterInterface; |
19 | 20 | use Symfony\Component\Cache\Adapter\ApcuAdapter; |
| 21 | +use Symfony\Component\Cache\Adapter\ArrayAdapter; |
20 | 22 | use Symfony\Component\Cache\Adapter\ChainAdapter; |
21 | 23 | use Symfony\Component\Cache\Adapter\DoctrineAdapter; |
22 | 24 | use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
|
27 | 29 | use Symfony\Component\DependencyInjection\Loader\ClosureLoader; |
28 | 30 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
29 | 31 | use Symfony\Component\DependencyInjection\Reference; |
| 32 | +use Symfony\Component\PropertyAccess\PropertyAccessor; |
30 | 33 | use Symfony\Component\Serializer\Serializer; |
31 | 34 | use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory; |
32 | 35 | use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader; |
@@ -70,6 +73,32 @@ public function testPropertyAccessWithOverriddenValues() |
70 | 73 | $this->assertTrue($def->getArgument(1)); |
71 | 74 | } |
72 | 75 |
|
| 76 | + public function testPropertyAccessCache() |
| 77 | + { |
| 78 | + $container = $this->createContainerFromFile('property_accessor'); |
| 79 | + |
| 80 | + if (!method_exists(PropertyAccessor::class, 'createCache')) { |
| 81 | + return $this->assertFalse($container->hasDefinition('cache.property_access')); |
| 82 | + } |
| 83 | + |
| 84 | + $cache = $container->getDefinition('cache.property_access'); |
| 85 | + $this->assertSame(array(PropertyAccessor::class, 'createCache'), $cache->getFactory(), 'PropertyAccessor::createCache() should be used in non-debug mode'); |
| 86 | + $this->assertSame(AdapterInterface::class, $cache->getClass()); |
| 87 | + } |
| 88 | + |
| 89 | + public function testPropertyAccessCacheWithDebug() |
| 90 | + { |
| 91 | + $container = $this->createContainerFromFile('property_accessor', array('kernel.debug' => true)); |
| 92 | + |
| 93 | + if (!method_exists(PropertyAccessor::class, 'createCache')) { |
| 94 | + return $this->assertFalse($container->hasDefinition('cache.property_access')); |
| 95 | + } |
| 96 | + |
| 97 | + $cache = $container->getDefinition('cache.property_access'); |
| 98 | + $this->assertNull($cache->getFactory()); |
| 99 | + $this->assertSame(ArrayAdapter::class, $cache->getClass(), 'ArrayAdapter should be used in debug mode'); |
| 100 | + } |
| 101 | + |
73 | 102 | /** |
74 | 103 | * @expectedException \LogicException |
75 | 104 | * @expectedExceptionMessage CSRF protection needs sessions to be enabled. |
|
0 commit comments