Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
test/DependencyInjection/CompilerPass/NotificationsCompilerPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/* | ||
* This file is part of the Exchange Rate Bundle, an RunOpenCode project. | ||
* | ||
* (c) 2017 RunOpenCode | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace RunOpenCode\Bundle\ExchangeRate\Tests\DependencyInjection\CompilerPass; | ||
|
||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass\NotificationsCompilerPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
/** | ||
* Class NotificationsCompilerPassTest | ||
* | ||
* @package RunOpenCode\Bundle\ExchangeRate\Tests\DependencyInjection\CompilerPass | ||
*/ | ||
class NotificationsCompilerPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function itRemovesEmailEventListenerWhenEmailNotificationsAreDisabled() | ||
{ | ||
$this->setDefinition('runopencode.exchange_rate.notifications.email', new Definition()); | ||
|
||
$this->compile(); | ||
|
||
$this->assertFalse($this->container->has('runopencode.exchange_rate.notifications.email')); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException | ||
*/ | ||
public function itThrowsExceptionWhenMailerServiceIsMissing() | ||
{ | ||
$this->setParameter('runopencode.exchange_rate.notifications.email.recipients', []); | ||
$this->setDefinition('runopencode.exchange_rate.notifications.email', new Definition()); | ||
|
||
$this->compile(); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException | ||
*/ | ||
public function itThrowsExceptionWhenThereAreNoEmailRecipients() | ||
{ | ||
$this->setParameter('runopencode.exchange_rate.notifications.email.recipients', []); | ||
$this->setDefinition('runopencode.exchange_rate.notifications.email', new Definition()); | ||
$this->setDefinition('mailer', new Definition()); | ||
|
||
$this->compile(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itSetsRecipientsForEmailNotifications() | ||
{ | ||
$this->setParameter('runopencode.exchange_rate.notifications.email.recipients', ['test@test.test']); | ||
$this->setDefinition('runopencode.exchange_rate.notifications.email', new Definition(null, [ 'arg1', 'arg2' ])); | ||
$this->setDefinition('mailer', new Definition()); | ||
|
||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithArgument('runopencode.exchange_rate.notifications.email', 2, ['test@test.test']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function registerCompilerPass(ContainerBuilder $container) | ||
{ | ||
$container | ||
->addCompilerPass(new NotificationsCompilerPass()); | ||
} | ||
} |