-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Werkspot/be_able_to_throw_exceptions
Be able to throw exceptions
- Loading branch information
Showing
5 changed files
with
83 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Postmark; | ||
|
||
class ThrowExceptionOnFailurePlugin implements \Swift_Events_ResponseListener | ||
{ | ||
public function responseReceived(\Swift_Events_ResponseEvent $event) | ||
{ | ||
if (!$event->isValid()) { | ||
throw new \Swift_TransportException($event->getResponse()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Postmark\ThrowExceptionOnFailurePlugin; | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
class ThrowExceptionOnFailurePluginTest extends TestCase { | ||
|
||
/** | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function testValidResponseThrowsNoException() | ||
{ | ||
$valid = true; | ||
$event = new \Swift_Events_ResponseEvent(new \Postmark\Transport('SERVER_TOKEN'), 'success', $valid); | ||
|
||
$plugin = new ThrowExceptionOnFailurePlugin(); | ||
$plugin->responseReceived($event); // no exception | ||
} | ||
|
||
public function testInvalidResponseThrowsException() | ||
{ | ||
$valid = false; | ||
$event = new \Swift_Events_ResponseEvent(new \Postmark\Transport('SERVER_TOKEN'), 'invalid response', $valid); | ||
|
||
$plugin = new ThrowExceptionOnFailurePlugin(); | ||
|
||
$this->expectException(\Swift_TransportException::class); | ||
$this->expectExceptionMessage('invalid response'); | ||
|
||
$plugin->responseReceived($event); | ||
} | ||
} |
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