Completed
Pull Request — master (#1163)
by
unknown
01:39
created

testSchemaSubscriberWiring()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.069
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\Cache\Adapter\PdoAdapter;
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();
22
        }
23
24
        $container = new ContainerBuilder(new ParameterBag([
25
            'kernel.name' => 'app',
26
            'kernel.debug' => false,
27
            'kernel.bundles' => [],
28
            'kernel.cache_dir' => sys_get_temp_dir(),
29
            'kernel.environment' => 'test',
30
            'kernel.root_dir' => __DIR__ . '/../../../../', // src dir
31
            'kernel.project_dir' => __DIR__ . '/../../../../', // src dir
32
            'kernel.bundles_metadata' => [],
33
            'kernel.charset' => 'UTF-8',
34
            'kernel.container_class' => ContainerBuilder::class,
35
            'kernel.secret' => 'test',
36
            'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo',
37
        ]));
38
39
        $extension = new FrameworkExtension();
40
        $container->registerExtension($extension);
41
        $extension->load([
42
            'framework' => [
43
                'cache' => ['app' => 'cache.adapter.pdo'],
44
            ],
45
        ], $container);
46
47
        $extension = new DoctrineExtension();
48
        $container->registerExtension($extension);
49
        $extension->load([
50
            [
51
                'dbal' => [],
52
                'orm' => [],
53
            ],
54
        ], $container);
55
56
        $container->setAlias('test_subscriber_alias', new Alias('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', true));
57
        // prevents cache.app from inlining, which affects the assertion
58
        $container->register('test_needs_cache_app', 'stdClass')
59
            ->setArgument(0, new Reference('cache.app'));
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_subscriber_alias');
67
        $this->assertEquals([new Reference('cache.app')], $definition->getArgument(0));
68
    }
69
}
70