Completed
Push — master ( a4a434...c34bf1 )
by Ross
10:09
created

DoctrineMiddlewarePassTest::testProcess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 56
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 9.7251
c 0
b 0
f 0
cc 2
eloc 40
nc 2
nop 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A DoctrineMiddlewarePassTest::test_do_not_process_when_there_are_no_entity_managers() 0 11 2
A DoctrineMiddlewarePassTest::test_do_not_process_when_tactician_doctrine_is_not_installed() 0 14 2

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 League\Tactician\Bundle\Tests\DependencyInjection\Compiler;
4
5
use League\Tactician\Bundle\DependencyInjection\Compiler\DoctrineMiddlewarePass;
6
use League\Tactician\Doctrine\ORM\TransactionMiddleware;
7
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
class DoctrineMiddlewarePassTest extends AbstractCompilerPassTestCase
12
{
13
    protected function registerCompilerPass(ContainerBuilder $container)
14
    {
15
        $container->addCompilerPass(new DoctrineMiddlewarePass());
16
    }
17
18
    public function test_registering_middleware_for_multiple_entity_managers()
19
    {
20
        if (!class_exists(TransactionMiddleware::class)) {
21
            $this->markTestSkipped('"league/tactician-doctrine" is not installed');
22
        }
23
24
        $this->setParameter(
25
            'doctrine.entity_managers',
26
            [
27
                'default' => 'doctrine.orm.default_entity_manager',
28
                'second' => 'doctrine.orm.second_entity_manager',
29
            ]
30
        );
31
        $this->setParameter('doctrine.default_entity_manager', 'default');
32
33
        $this->compile();
34
35
        $this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.doctrine.default', 0, new Reference('doctrine.orm.default_entity_manager'));
36
        $this->assertContainerBuilderHasServiceDefinitionWithArgument('tactician.middleware.doctrine.second', 0, new Reference('doctrine.orm.second_entity_manager'));
37
        $this->assertContainerBuilderHasAlias('tactician.middleware.doctrine', 'tactician.middleware.doctrine.default');
38
    }
39
40
    public function test_do_not_process_when_there_are_no_entity_managers()
41
    {
42
        if (!class_exists(TransactionMiddleware::class)) {
43
            $this->markTestSkipped('"league/tactician-doctrine" is not installed');
44
        }
45
46
        $this->compile();
47
48
        $this->assertEmpty($this->container->getDefinitions());
49
        $this->assertEmpty($this->container->getAliases());
50
    }
51
52
    public function test_do_not_process_when_tactician_doctrine_is_not_installed()
53
    {
54
        if (class_exists(TransactionMiddleware::class)) {
55
            $this->markTestSkipped('"league/tactician-doctrine" is installed');
56
        }
57
58
        $this->setParameter('doctrine.entity_managers', ['default' => 'doctrine.orm.default_entity_manager']);
59
        $this->setParameter('doctrine.default_entity_manager', 'default');
60
61
        $this->compile();
62
63
        $this->assertEmpty($this->container->getDefinitions());
64
        $this->assertEmpty($this->container->getAliases());
65
    }
66
}
67