1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\NotificationBundle\Tests\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
17
|
|
|
use Sonata\NotificationBundle\DependencyInjection\SonataNotificationExtension; |
18
|
|
|
|
19
|
|
|
final class SonataNotificationExtensionTest extends AbstractExtensionTestCase |
20
|
|
|
{ |
21
|
|
|
protected function setUp(): void |
22
|
|
|
{ |
23
|
|
|
parent::setUp(); |
24
|
|
|
$this->container->setParameter('kernel.bundles', [ |
25
|
|
|
'SonataDoctrineBundle' => true, |
26
|
|
|
'SonataAdminBundle' => true, |
27
|
|
|
]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testEmptyConfig(): void |
31
|
|
|
{ |
32
|
|
|
$this->load(); |
33
|
|
|
|
34
|
|
|
$this->assertContainerBuilderHasAlias('sonata.notification.backend', 'sonata.notification.backend.runtime'); |
35
|
|
|
$this->assertContainerBuilderHasService('sonata.notification.consumer.swift_mailer'); |
36
|
|
|
$this->assertContainerBuilderHasService('sonata.notification.consumer.logger'); |
37
|
|
|
$this->assertContainerBuilderHasParameter('sonata.notification.backend', 'sonata.notification.backend.runtime'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testDoNotRegisterDefaultConsumers(): void |
41
|
|
|
{ |
42
|
|
|
$this->load([ |
43
|
|
|
'consumers' => [ |
44
|
|
|
'register_default' => false, |
45
|
|
|
], |
46
|
|
|
]); |
47
|
|
|
|
48
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.consumer.swift_mailer'); |
49
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.consumer.logger'); |
50
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.manager.message.default'); |
51
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.erroneous_messages_selector'); |
52
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.event.doctrine_optimize'); |
53
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.event.doctrine_backend_optimize'); |
54
|
|
|
|
55
|
|
|
$this->assertContainerBuilderHasParameter('sonata.notification.event.iteration_listeners', []); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testDoctrineBackendNoConfig(): void |
59
|
|
|
{ |
60
|
|
|
$this->expectException(\RuntimeException::class); |
61
|
|
|
$this->expectExceptionMessage('Please configure the sonata_notification.backends.doctrine section'); |
62
|
|
|
|
63
|
|
|
$this->load([ |
64
|
|
|
'backend' => 'sonata.notification.backend.doctrine', |
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testDoctrineBackend(): void |
69
|
|
|
{ |
70
|
|
|
$this->load([ |
71
|
|
|
'backend' => 'sonata.notification.backend.doctrine', |
72
|
|
|
'backends' => [ |
73
|
|
|
'doctrine' => null, |
74
|
|
|
], |
75
|
|
|
'consumers' => [ |
76
|
|
|
'register_default' => false, |
77
|
|
|
], |
78
|
|
|
]); |
79
|
|
|
|
80
|
|
|
$this->assertContainerBuilderHasService('sonata.notification.manager.message.default'); |
81
|
|
|
$this->assertContainerBuilderHasService('sonata.notification.erroneous_messages_selector'); |
82
|
|
|
$this->assertContainerBuilderHasService('sonata.notification.event.doctrine_optimize'); |
83
|
|
|
$this->assertContainerBuilderHasService('sonata.notification.event.doctrine_backend_optimize'); |
84
|
|
|
|
85
|
|
|
$this->assertContainerBuilderHasParameter('sonata.notification.event.iteration_listeners', [ |
86
|
|
|
'sonata.notification.event.doctrine_backend_optimize', |
87
|
|
|
]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testRabbitMQBackendNoConfig(): void |
91
|
|
|
{ |
92
|
|
|
$this->expectException(\RuntimeException::class); |
93
|
|
|
$this->expectExceptionMessage('Please configure the sonata_notification.backends.rabbitmq section'); |
94
|
|
|
|
95
|
|
|
$this->load([ |
96
|
|
|
'backend' => 'sonata.notification.backend.rabbitmq', |
97
|
|
|
]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testRabbitMQBackend(): void |
101
|
|
|
{ |
102
|
|
|
$this->load([ |
103
|
|
|
'backend' => 'sonata.notification.backend.rabbitmq', |
104
|
|
|
'backends' => [ |
105
|
|
|
'rabbitmq' => [ |
106
|
|
|
'exchange' => 'logs', |
107
|
|
|
], |
108
|
|
|
], |
109
|
|
|
'consumers' => [ |
110
|
|
|
'register_default' => false, |
111
|
|
|
], |
112
|
|
|
]); |
113
|
|
|
|
114
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.manager.message.default'); |
115
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.erroneous_messages_selector'); |
116
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.event.doctrine_optimize'); |
117
|
|
|
$this->assertContainerBuilderNotHasService('sonata.notification.event.doctrine_backend_optimize'); |
118
|
|
|
|
119
|
|
|
$this->assertContainerBuilderHasParameter('sonata.notification.event.iteration_listeners', []); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
protected function getContainerExtensions(): array |
123
|
|
|
{ |
124
|
|
|
return [ |
125
|
|
|
new SonataNotificationExtension(), |
126
|
|
|
]; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|