|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheSchemaSubscriberPass; |
|
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; |
|
7
|
|
|
use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
14
|
|
|
|
|
15
|
|
|
class CacheSchemaSubscriberTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function testSchemaSubscriberWiring() : void |
|
18
|
|
|
{ |
|
19
|
|
|
if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) { |
|
20
|
|
|
$this->markTestSkipped('This test requires Symfony 5.1 or higher'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$container = new ContainerBuilder(new ParameterBag([ |
|
24
|
|
|
'kernel.name' => 'app', |
|
25
|
|
|
'kernel.debug' => false, |
|
26
|
|
|
'kernel.bundles' => [], |
|
27
|
|
|
'kernel.cache_dir' => sys_get_temp_dir(), |
|
28
|
|
|
'kernel.environment' => 'test', |
|
29
|
|
|
'kernel.root_dir' => __DIR__ . '/../../../../', // src dir |
|
30
|
|
|
'kernel.project_dir' => __DIR__ . '/../../../../', // src dir |
|
31
|
|
|
'kernel.bundles_metadata' => [], |
|
32
|
|
|
'kernel.charset' => 'UTF-8', |
|
33
|
|
|
'kernel.container_class' => ContainerBuilder::class, |
|
34
|
|
|
'kernel.secret' => 'test', |
|
35
|
|
|
'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo', |
|
36
|
|
|
])); |
|
37
|
|
|
|
|
38
|
|
|
$extension = new FrameworkExtension(); |
|
39
|
|
|
$container->registerExtension($extension); |
|
40
|
|
|
$extension->load([ |
|
41
|
|
|
'framework' => [ |
|
42
|
|
|
'cache' => [ |
|
43
|
|
|
'pools' => [ |
|
44
|
|
|
'my_cache_adapter' => ['adapter' => 'cache.adapter.pdo'], |
|
45
|
|
|
], |
|
46
|
|
|
], |
|
47
|
|
|
], |
|
48
|
|
|
], $container); |
|
49
|
|
|
|
|
50
|
|
|
$extension = new DoctrineExtension(); |
|
51
|
|
|
$container->registerExtension($extension); |
|
52
|
|
|
$extension->load([ |
|
53
|
|
|
[ |
|
54
|
|
|
'dbal' => [], |
|
55
|
|
|
'orm' => [], |
|
56
|
|
|
], |
|
57
|
|
|
], $container); |
|
58
|
|
|
|
|
59
|
|
|
$container->setAlias('test_subscriber_alias', new Alias('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', true)); |
|
60
|
|
|
// prevent my_cache_apapter from inlining |
|
61
|
|
|
$container->register('uses_my_cache_adapter', 'stdClass') |
|
62
|
|
|
->addArgument(new Reference('my_cache_adapter')) |
|
63
|
|
|
->setPublic(true); |
|
64
|
|
|
$container->addCompilerPass(new CacheSchemaSubscriberPass(), PassConfig::TYPE_OPTIMIZE, -10); |
|
65
|
|
|
$container->compile(); |
|
66
|
|
|
|
|
67
|
|
|
// check that PdoAdapter service is injected as an argument |
|
68
|
|
|
$definition = $container->findDefinition('test_subscriber_alias'); |
|
69
|
|
|
$this->assertEquals([new Reference('my_cache_adapter')], $definition->getArgument(0)); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|