/
MessengerPassTest.php
69 lines (54 loc) · 2.67 KB
/
MessengerPassTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace DependencyInjection\Compiler;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\MessengerPass;
use PHPUnit\Framework\TestCase;
use stdClass;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Messenger\MessageBus;
use Symfony\Component\Messenger\MessageBusInterface;
class MessengerPassTest extends TestCase
{
protected function setUp()
{
if (interface_exists(MessageBusInterface::class)) {
return;
}
$this->markTestSkipped('Symfony Messenger component is not installed');
}
public function testRemovesDefinitionsWhenMessengerComponentIsDisabled()
{
$pass = new MessengerPass();
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config'));
$loader->load('messenger.xml');
$pass->process($container);
$this->assertFalse($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction'));
$this->assertFalse($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware'));
}
public function testRemoveDefinitionsWhenHasAliasButNotMessengerComponent()
{
$pass = new MessengerPass();
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config'));
$loader->load('messenger.xml');
$container->register('some_other_bus', stdClass::class);
$container->setAlias('message_bus', 'some_other_bus');
$pass->process($container);
$this->assertFalse($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction'));
$this->assertFalse($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware'));
}
public function testDoesNotRemoveDefinitionsWhenMessengerComponentIsEnabled()
{
$pass = new MessengerPass();
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config'));
$loader->load('messenger.xml');
$container->register('messenger.bus.default', MessageBus::class);
$container->setAlias('message_bus', 'messenger.bus.default');
$pass->process($container);
$this->assertTrue($container->hasDefinition('doctrine.orm.messenger.middleware_factory.transaction'));
$this->assertTrue($container->hasDefinition('messenger.middleware.doctrine_transaction_middleware'));
}
}