8000 minor #40844 [FrameworkBundle] Add basic tests for the notifier frame… · symfony/symfony@3fd41ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 3fd41ce

Browse files
committed
minor #40844 [FrameworkBundle] Add basic tests for the notifier framework bundle integration (jschaedl)
This PR was merged into the 5.3-dev branch. Discussion ---------- [FrameworkBundle] Add basic tests for the notifier framework bundle integration | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | <!-- required for new features --> This PR adds basic tests for the notifier framework bundle integration: - [x] Adjust the symfony-1.0.xsd and define the notifier type - [x] Add general notifier configuration tests in FrameworkExtensionTest Commits ------- 47088eb Add basic notifier tests
2 parents f342892 + 47088eb commit 3fd41ce

15 files changed

+303
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<xsd:element name="http-cache" type="http_cache" minOccurs="0" maxOccurs="1" />
3737
<xsd:element name="rate-limiter" type="rate_limiter" minOccurs="0" maxOccurs="1" />
3838
<xsd:element name="uid" type="uid" minOccurs="0" maxOccurs="1" />
39+
<xsd:element name="notifier" type="notifier" minOccurs="0" maxOccurs="1" />
3940
</xsd:choice>
4041

4142
<xsd:attribute name="http-method-override" type="xsd:boolean" />
@@ -627,6 +628,7 @@
627628
<xsd:element name="envelope" type="mailer_envelope" minOccurs="0" maxOccurs="1" />
628629
<xsd:element name="header" type="header" minOccurs="0" maxOccurs="unbounded" />
629630
</xsd:sequence>
631+
<xsd:attribute name="enabled" type="xsd:boolean" />
630632
<xsd:attribute name="dsn" type="xsd:string" />
631633
<xsd:attribute name="message-bus" type="xsd:string" />
632634
</xsd:complexType>
@@ -727,4 +729,42 @@
727729
<xsd:enumeration value="1" />
728730
</xsd:restriction>
729731
</xsd:simpleType>
732+
733+
<xsd:complexType name="notifier">
734+
<xsd:sequence>
735+
<xsd:element name="chatter-transport" type="chatter-transport" minOccurs="0" maxOccurs="unbounded" />
736+
<xsd:element name="texter-transport" type="texter-transport" minOccurs="0" maxOccurs="unbounded" />
737+
<xsd:element name="channel-policy" type="channel-policy" minOccurs="0" maxOccurs="unbounded" />
738+
<xsd:element name="admin-recipients" type="admin-recipients" minOccurs="0" maxOccurs="1" />
739+
</xsd:sequence>
740+
<xsd:attribute name="enabled" type="xsd:boolean" />
741+
<xsd:attribute name="notification-on-failed-messages" type="xsd:boolean" />
742+
<xsd:attribute name="message-bus" type="xsd:string" />
743+
</xsd:complexType>
744+
745+
<xsd:complexType name="chatter-transport" mixed="true">
746+
<xsd:attribute name="name" type="xsd:string" use="required"/>
747+
</xsd:complexType>
748+
749+
<xsd:complexType name="texter-transport" mixed="true">
750+
<xsd:attribute name="name" type="xsd:string" use="required"/>
751+
</xsd:complexType>
752+
753+
<xsd:complexType name="channel-policy" mixed="true">
754+
<xsd:sequence>
755+
<xsd:element name="channel" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
756+
</xsd:sequence>
757+
<xsd:attribute name="name" type="xsd:string" use="required" />
758+
</xsd:complexType>
759+
760+
<xsd:complexType name="admin-recipients" mixed="true">
761+
<xsd:sequence>
762+
<xsd:element name="admin-recipient" type="admin-recipient" minOccurs="1" maxOccurs="unbounded" />
763+
</xsd:sequence>
764+
</xsd:complexType>
765+
766+
<xsd:complexType name="admin-recipient" mixed="true">
767+
<xsd:attribute name="email" type="xsd:string" use="required" />
768+
<xsd:attribute name="phone" type="xsd:string" />
769+
</xsd:complexType>
730770
</xsd:schema>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Symfony\Bundl 10000 e\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
5+
6+
$container->loadFromExtension('framework', [
7+
'messenger' => null,
8+
'mailer' => [
9+
'dsn' => 'smtp://example.com',
10+
],
11+
'notifier' => [
12+
'enabled' => true,
13+
'notification_on_failed_messages' => true,
14+
'chatter_transports' => [
15+
'slack' => 'null'
16+
],
17+
'texter_transports' => [
18+
'twilio' => 'null'
19+
],
20+
'channel_policy' => [
21+
'low' => ['slack'],
22+
'high' => ['slack', 'twilio'],
23+
],
24+
'admin_recipients' => [
25+
['email' => 'test@test.de', 'phone' => '+490815',],
26+
]
27+
],
28+
]);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
5+
6+
$container->loadFromExtension('framework', [
7+
'mailer' => [
8+
'enabled' => false,
9+
],
10+
'messenger' => [
11+
'enabled' => true,
12+
],
13+
'notifier' => [
14+
'enabled' => true,
15+
'notification_on_failed_messages' => true,
16+
'chatter_transports' => [
17+
'slack' => 'null'
18+
],
19+
'texter_transports' => [
20+
'twilio' => 'null'
21+
],
22+
'channel_policy' => [
23+
'low' => ['slack'],
24+
'high' => ['slack', 'twilio'],
25+
],
26+
'admin_recipients' => [
27+
['email' => 'test@test.de', 'phone' => '+490815',],
28+
]
29+
],
30+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
5+
6+
$container->loadFromExtension('framework', [
7+
'mailer' => [
8+
'dsn' => 'smtp://example.com',
9+
],
10+
'messenger' => [
11+
'enabled' => false,
12+
],
13+
'notifier' => [
14+
'enabled' => true,
15+
'notification_on_failed_messages' => true,
16+
'chatter_transports' => [
17+
'slack' => 'null'
18+
],
19+
'texter_transports' => [
20+
'twilio' => 'null'
21+
],
22+
'channel_policy' => [
23+
'low' => ['slack'],
24+
'high' => ['slack', 'twilio'],
25+
],
26+
'admin_recipients' => [
27+
['email' => 'test@test.de', 'phone' => '+490815',],
28+
]
29+
],
30+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\BarMessage;
4+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Messenger\FooMessage;
5+
6+
$container->loadFromExtension('framework', [
7+
'notifier' => [
8+
'enabled' => true,
9+
],
10+
]);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:messenger enabled="true" />
10+
<framework:mailer dsn="smtp://example.com" />
11+
<framework:notifier enabled="true" notification-on-failed-messages="true">
12+
<framework:chatter-transport name="slack">null</framework:chatter-transport>
13+
<framework:texter-transport name="twilio">null</framework:texter-transport>
14+
<framework:channel-policy name="low">slack</framework:channel-policy>
15+
<framework:channel-policy name="high">twilio</framework:channel-policy>
16+
<framework:admin-recipients>
17+
<framework:admin-recipient email="test@test.de" phone="+490815" />
18+
</framework:admin-recipients>
19+
</framework:notifier>
20+
</framework:config>
21+
</container>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:mailer enabled="false" />
10+
<framework:messenger enabled="true" />
11+
<framework:notifier enabled="true" notification-on-failed-messages="true">
12+
<framework:chatter-transport name="slack">null</framework:chatter-transport>
13+
<framework:texter-transport name="twilio">null</framework:texter-transport>
14+
<framework:channel-policy name="low">slack</framework:channel-policy>
15+
<framework:channel-policy name="high">twilio</framework:channel-policy>
16+
<framework:admin-recipients>
17+
<framework:admin-recipient email="test@test.de" phone="+490815" />
18+
</framework:admin-recipients>
19+
</framework:notifier>
20+
</framework:config>
21+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:mailer dsn="smtp://example.com" />
10+
<framework:messenger enabled="false" />
11+
<framework:notifier enabled="true" notification-on-failed-messages="true">
12+
<framework:chatter-transport name="slack">null</framework:chatter-transport>
13+
<framework:texter-transport name="twilio">null</framework:texter-transport>
14+
<framework:channel-policy name="low">slack</framework:channel-policy>
15+
<framework:channel-policy name="high">twilio</framework:channel-policy>
16+
<framework:admin-recipients>
17+
<framework:admin-recipient email="test@test.de" phone="+490815" />
18+
</framework:admin-recipients>
19+
</framework:notifier>
20+
</framework:config>
21+
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:notifier enabled="true"></framework:notifier>
10+
</framework:config>
11+
</container>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
framework:
2+
messenger: ~
3+
mailer:
4+
dsn: 'smtp://example.com'
5+
notifier:
6+
enabled: true
7+
notification_on_failed_messages: true
8+
chatter_transports:
9+
slack: 'null'
10+
texter_transports:
11+
twilio: 'null'
12+
channel_policy:
13+
low: ['slack']
14+
10000 high: ['slack', 'twilio']
15+
admin_recipients:
16+
- { email: 'test@test.de', phone: '+490815' }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
framework:
2+
mailer:
3+
enabled: false
4+
messenger:
5+
enabled: true
6+
notifier:
7+
enabled: true
8+
notification_on_failed_messages: true
9+
chatter_transports:
10+
slack: 'null'
11+
texter_transports:
12+
twilio: 'null'
13+
channel_policy:
14+
low: ['slack']
15+
high: ['slack', 'twilio']
16+
admin_recipients:
17+
- { email: 'test@test.de', phone: '+490815' }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
framework:
2+
mailer:
3+
dsn: 'smtp://example.com'
4+
messenger:
5+
enabled: false
6+
notifier:
7+
enabled: true
8+
notification_on_failed_messages: true
9+
chatter_transports:
10+
slack: 'null'
11+
texter_transports:
12+
twilio: 'null'
13+
channel_policy:
14+
low: ['slack']
15+
high: ['slack', 'twilio']
16+
admin_recipients:
17+
- { email: 'test@test.de', phone: '+490815' }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
notifier:
3+
enabled: true

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,43 @@ public function testRegisterParameterCollectingBehaviorDescribingTags()
18361836
], $container->getParameter('container.behavior_describing_tags'));
18371837
}
18381838

1839+
public function testNotifierWithoutMailer()
1840+
{
1841+
$container = $this->createContainerFromFile('notifier_without_mailer');
1842+
1843+
$this->assertFalse($container->hasDefinition('notifier.channel.email'));
1844+
}
1845+
1846+
public function testNotifierWithoutMessenger()
1847+
{
1848+
$container = $this->createContainerFromFile('notifier_without_messenger');
1849+
1850+
$this->assertFalse($container->getDefinition('notifier.failed_message_listener')->hasTag('kernel.event_subscriber'));
1851+
}
1852+
1853+
public function testNotifierWithMailerAndMessenger()
1854+
{
1855+
$container = $this->createContainerFromFile('notifier');
1856+
1857+
$this->assertTrue($container->hasDefinition('notifier'));
1858+
$this->assertTrue($container->hasDefinition('chatter'));
1859+
$this->assertTrue($container->hasDefinition('texter'));
1860+
$this->assertTrue($container->hasDefinition('notifier.channel.chat'));
1861+
$this->assertTrue($container->hasDefinition('notifier.channel.email'));
1862+
$this->assertTrue($container->hasDefinition('notifier.channel.sms'));
1863+
$this->assertTrue($container->hasDefinition('notifier.channel_policy'));
1864+
$this->assertTrue($container->getDefinition('notifier.failed_message_listener')->hasTag('kernel.event_subscriber'));
1865+
}
1866+
1867+
public function testNotifierWithoutTransports()
1868+
{
1869+
$container = $this->createContainerFromFile('notifier_without_transports');
1870+
1871+
$this->assertTrue($container->hasDefinition('notifier'));
1872+
$this->assertFalse($container->hasDefinition('chatter'));
1873+
$this->assertFalse($container->hasDefinition('texter'));
1874+
}
1875+
18391876
protected function createContainer(array $data = [])
18401877
{
18411878
return new ContainerBuilder(new EnvPlaceholderParameterBag(array_merge([

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"symfony/mailer": "^5.2",
5151
"symfony/messenger": "^5.2",
5252
"symfony/mime": "^4.4|^5.0",
53+
"symfony/notifier": "^5.3",
5354
"symfony/process": "^4.4|^5.0",
5455
"symfony/rate-limiter": "^5.2",
5556
"symfony/security-bundle": "^5.3",

0 commit comments

Comments
 (0)
0