forked from lexik/LexikMailerBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
90 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\MailerBundle\Exception; | ||
|
||
/** | ||
* @author Yannick Snobbert <[email protected]> | ||
*/ | ||
class ReferenceNotFoundException extends \Exception | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $reference; | ||
|
||
/** | ||
* @param string $reference | ||
* @param string $message | ||
* @param int $code | ||
* @param \Exception | ||
*/ | ||
public function __construct($reference, $message = null, \Exception $previous = null, $code = 0) | ||
{ | ||
$this->reference = $reference; | ||
|
||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
/** | ||
* Get reference | ||
* | ||
* @return string | ||
*/ | ||
public function getReference() | ||
{ | ||
return $this->reference; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
|
||
namespace Lexik\Bundle\MailerBundle\Tests\Message; | ||
|
||
use Lexik\Bundle\MailerBundle\Exception\ReferenceNotFoundException; | ||
use Lexik\Bundle\MailerBundle\Twig\Loader\EmailLoader; | ||
|
||
use Lexik\Bundle\MailerBundle\Message\MessageRenderer; | ||
use Lexik\Bundle\MailerBundle\Message\MessageFactory; | ||
use Lexik\Bundle\MailerBundle\Tests\Unit\BaseUnitTestCase; | ||
|
@@ -53,16 +53,11 @@ public function testGetErrorMessages() | |
$file = __FILE__; | ||
$body = <<<EOF | ||
An error occurred while trying to send an email. | ||
You tried to use a reference that does not exist : "this-reference-does-not-exixt" | ||
You tried to use a reference that does not exist : "this-reference-does-not-exist" | ||
in "{$file}" at line 60 | ||
EOF; | ||
|
||
$message = $factory->get('this-reference-does-not-exixt', '[email protected]', array('name' => 'chuck')); | ||
$this->assertInstanceOf('Swift_Message', $message); | ||
$this->assertEquals(array('[email protected]' => null), $message->getTo()); | ||
$this->assertEquals('An exception occurred', $message->getSubject()); | ||
$this->assertEquals($body, $message->getBody()); | ||
$this->assertEquals(array('[email protected]' => null), $message->getFrom()); | ||
$message = $factory->get('this-reference-does-not-exist', '[email protected]', array('name' => 'chuck')); | ||
|
||
// no translation found | ||
$body = <<<EOF | ||
|
@@ -125,4 +120,20 @@ protected function createMessageFactory() | |
|
||
return new MessageFactory($this->em, $renderer, $annotationDriver, $options, $signerFactory); | ||
} | ||
|
||
public function testGetEmail() | ||
{ | ||
$factory = $this->createMessageFactory(); | ||
|
||
$email = $factory->getEmail('rabbids-template', false); | ||
$this->assertInstanceOf('Lexik\Bundle\MailerBundle\Model\EmailInterface', $email); | ||
$this->assertEquals($email->getReference(), 'rabbids-template'); | ||
|
||
$email = $factory->getEmail('this-reference-does-not-exist', false); | ||
$this->assertNull($email); | ||
|
||
$this->setExpectedException('Lexik\Bundle\MailerBundle\Exception\ReferenceNotFoundException'); | ||
$factory = $this->createMessageFactory(); | ||
$factory->getEmail('this-reference-does-not-exist', true); | ||
} | ||
} |
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