Completed
Pull Request — master (#817)
by Maxime
02:16
created

testRemoveDefinitionsWhenHasAliasButNotMessengerComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace DependencyInjection\Compiler;
4
5
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\MessengerPass;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
10
use Symfony\Component\Messenger\MessageBus;
11
use Symfony\Component\Messenger\MessageBusInterface;
12
13
class MessengerPassTest extends TestCase
14
{
15
    protected function setUp()
16
    {
17
        if (interface_exists(MessageBusInterface::class)) {
18
            return;
19
        }
20
21
        $this->markTestSkipped('Symfony Messenger component is not installed');
22
    }
23
24
    public function testRemovesDefinitionsWhenMessengerComponentIsDisabled()
25
    {
26
        $pass      = new MessengerPass();
27
        $container = new ContainerBuilder();
28
        $loader    = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config'));
29
        $loader->load('messenger.xml');
30
31
        $pass->process($container);
32
33
        $this->assertFalse($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction'));
34
        $this->assertFalse($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware'));
35
    }
36
37 View Code Duplication
    public function testRemoveDefinitionsWhenHasAliasButNotMessengerComponent()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $pass      = new MessengerPass();
40
        $container = new ContainerBuilder();
41
        $loader    = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config'));
42
        $loader->load('messenger.xml');
43
44
        $container->register('some_other_bus', \stdClass::class);
45
        $container->setAlias('message_bus', 'some_other_bus');
46
47
        $pass->process($container);
48
49
        $this->assertFalse($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction'));
50
        $this->assertFalse($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware'));
51
    }
52
53 View Code Duplication
    public function testDoesNotRemoveDefinitionsWhenMessengerComponentIsEnabled()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $pass      = new MessengerPass();
56
        $container = new ContainerBuilder();
57
        $loader    = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config'));
58
        $loader->load('messenger.xml');
59
60
        $container->register('messenger.bus.default', MessageBus::class);
61
        $container->setAlias('message_bus', 'messenger.bus.default');
62
63
        $pass->process($container);
64
65
        $this->assertTrue($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction'));
66
        $this->assertTrue($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware'));
67
    }
68
}
69