-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling of the EmailAction
The action now handles all sorts of errors the same. Specifically it can now display error messages from the email service if the app is in debug mode.
- Loading branch information
Showing
8 changed files
with
58 additions
and
19 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
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
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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Uniform\Tests\Actions; | ||
|
||
use Exception; | ||
use C as Config; | ||
use Uniform\Form; | ||
use Uniform\Tests\TestCase; | ||
use Uniform\Actions\EmailAction; | ||
|
@@ -167,6 +168,37 @@ public function testReceiveCopy() | |
$this->assertEquals('[email protected]', $action->params['replyTo']); | ||
$this->assertEquals('[email protected]', $action->params['from']); | ||
} | ||
|
||
public function testHandleServiceException() | ||
{ | ||
$this->form->data('field', 'value'); | ||
$action = new EmailAction($this->form, [ | ||
'service' => 'thrower', | ||
'to' => '[email protected]', | ||
'from' => '[email protected]', | ||
'subject' => 'Test', | ||
]); | ||
|
||
Config::set('debug', false); | ||
|
||
try { | ||
$action->perform(); | ||
$this->assertFalse(true); | ||
} catch (PerformerException $e) { | ||
// Language variables are not loaded in these tests so the message is empty | ||
// here. | ||
$this->assertEquals('.', $e->getMessage()); | ||
} | ||
|
||
Config::set('debug', true); | ||
|
||
try { | ||
$action->perform(); | ||
$this->assertFalse(true); | ||
} catch (PerformerException $e) { | ||
$this->assertEquals(": Throw it like it's hoot", $e->getMessage()); | ||
} | ||
} | ||
} | ||
|
||
class EmailActionStub extends EmailAction | ||
|
@@ -177,7 +209,9 @@ protected function sendEmail(array $params) | |
{ | ||
$this->calls++; | ||
$this->params = $params; | ||
return !isset($this->shouldFail); | ||
if (isset($this->shouldFail)) { | ||
throw new Exception('Failed'); | ||
} | ||
} | ||
|
||
protected function getSnippet($name, array $data) | ||
|
@@ -191,3 +225,7 @@ protected function getSnippet($name, array $data) | |
return $name; | ||
} | ||
} | ||
|
||
\Email::$services['thrower'] = function($email) { | ||
throw new Exception("Throw it like it's hoot"); | ||
}; |