Completed
Push — master ( 98e038...4b7885 )
by Andreas
21s queued 11s
created

testSchemaSubscriberWiring()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 9.0036
c 0
b 0
f 0
cc 2
nc 2
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 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