Completed
Pull Request — master (#1203)
by
unknown
04:38
created

testSchemaSubscriberWiring()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 8.9381
c 0
b 0
f 0
cc 3
nc 4
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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