Skip to content

Commit

Permalink
make it possible to use multiple to_email in XML
Browse files Browse the repository at this point in the history
The Configuration class allows to configure more than one recipient.
Since the to_email field was configured with XML configurations as
an attribute couldn't be specified multiple times.
  • Loading branch information
xabbuh committed Aug 18, 2014
1 parent 227bbee commit 44505b6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions Resources/config/schema/monolog-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<xsd:element name="excluded-404" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="tag" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="accepted-level" type="level" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="to-email" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="priority" type="xsd:integer" />
Expand Down
22 changes: 22 additions & 0 deletions Tests/DependencyInjection/FixtureMonologExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ public function testHandlersWithChannels()
);
}

public function testSingleEmailRecipient()
{
$container = $this->getContainer('single_email_recipient');

$this->assertSame(array(
array('setFrom', array('error@example.com')),
array('setTo', array(array('error@example.com'))),
array('setSubject', array('An Error Occurred!')),
), $container->getDefinition('monolog.handler.swift.mail_prototype')->getMethodCalls());
}

public function testMultipleEmailRecipients()
{
$container = $this->getContainer('multiple_email_recipients');

$this->assertSame(array(
array('setFrom', array('error@example.com')),
array('setTo', array(array('dev1@example.com', 'dev2@example.com'))),
array('setSubject', array('An Error Occurred!')),
), $container->getDefinition('monolog.handler.swift.mail_prototype')->getMethodCalls());
}

protected function getContainer($fixture)
{
$container = new ContainerBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">

<monolog:config>
<monolog:handler
name="swift"
type="swift_mailer"
from-email="error@example.com"
subject="An Error Occurred!"
level="debug">

<monolog:to-email>dev1@example.com</monolog:to-email>
<monolog:to-email>dev2@example.com</monolog:to-email>
</monolog:handler>
</monolog:config>
</container>
17 changes: 17 additions & 0 deletions Tests/DependencyInjection/Fixtures/xml/single_email_recipient.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/monolog http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">

<monolog:config>
<monolog:handler
name="swift"
type="swift_mailer"
from-email="error@example.com"
to-email="error@example.com"
subject="An Error Occurred!"
level="debug" />
</monolog:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
monolog:
handlers:
swift:
type: swift_mailer
from_email: error@example.com
to_email: [dev1@example.com, dev2@example.com]
subject: An Error Occurred!
level: debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
monolog:
handlers:
swift:
type: swift_mailer
from_email: error@example.com
to_email: error@example.com
subject: An Error Occurred!
level: debug

0 comments on commit 44505b6

Please sign in to comment.