1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Bundle\DoctrineBundle\Tests; |
4
|
|
|
|
5
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\CacheSchemaSubscriberPass; |
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; |
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; |
8
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
9
|
|
|
use Doctrine\ORM\EntityRepository; |
10
|
|
|
use Doctrine\ORM\QueryBuilder; |
11
|
|
|
use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestCustomClassRepoEntity; |
12
|
|
|
use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestCustomServiceRepoEntity; |
13
|
|
|
use Fixtures\Bundles\RepositoryServiceBundle\Entity\TestDefaultRepoEntity; |
14
|
|
|
use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomClassRepoRepository; |
15
|
|
|
use Fixtures\Bundles\RepositoryServiceBundle\Repository\TestCustomServiceRepoRepository; |
16
|
|
|
use Fixtures\Bundles\RepositoryServiceBundle\RepositoryServiceBundle; |
17
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension; |
18
|
|
|
use Symfony\Component\Cache\Adapter\PdoAdapter; |
19
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
20
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
23
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
24
|
|
|
|
25
|
|
|
class CacheSchemaSubscriberTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
public function testSchemaSubscriberWiring() : void |
28
|
|
|
{ |
29
|
|
|
$container = new ContainerBuilder(new ParameterBag([ |
30
|
|
|
'kernel.name' => 'app', |
31
|
|
|
'kernel.debug' => false, |
32
|
|
|
'kernel.bundles' => [], |
33
|
|
|
'kernel.cache_dir' => sys_get_temp_dir(), |
34
|
|
|
'kernel.environment' => 'test', |
35
|
|
|
'kernel.root_dir' => __DIR__ . '/../../../../', // src dir |
36
|
|
|
'kernel.project_dir' => __DIR__ . '/../../../../', // src dir |
37
|
|
|
'kernel.bundles_metadata' => [], |
38
|
|
|
'kernel.charset' => 'UTF-8', |
39
|
|
|
'kernel.container_class' => ContainerBuilder::class, |
40
|
|
|
'kernel.secret' => 'test', |
41
|
|
|
'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo', |
42
|
|
|
])); |
43
|
|
|
|
44
|
|
|
$extension = new FrameworkExtension(); |
45
|
|
|
$container->registerExtension($extension); |
46
|
|
|
$extension->load(['framework' => ['cache' => [ |
47
|
|
|
'app' => 'cache.adapter.pdo' |
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_alias', new Alias('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', true)); |
60
|
|
|
$container->addCompilerPass(new CacheSchemaSubscriberPass(), PassConfig::TYPE_OPTIMIZE, -10); |
61
|
|
|
$container->compile(); |
62
|
|
|
|
63
|
|
|
// sanity check |
64
|
|
|
$this->assertSame(PdoAdapter::class, $container->getDefinition('cache.app')->getClass()); |
65
|
|
|
// check that PdoAdapter service is injected as an argument |
66
|
|
|
$definition = $container->findDefinition('test_alias'); |
67
|
|
|
$this->assertEquals([new Reference('cache.app')], $definition->getArgument(0)); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|