Skip to content
Permalink
Browse files

Set exception code in flash params.

  • Loading branch information...
ADmad committed Jul 13, 2014
1 parent 8da0d6f commit bfe0db5dceaeaf00f94271bcee37e84c48e49a5b
@@ -66,14 +66,17 @@ public function __construct(ComponentRegistry $collection, array $config = []) {
* - `element` The element used to render the flash message
* - `params` An array of variables to make available when using an element
*
* @param string $message Message to be flashed
* @param string|\Exception $message Message to be flashed. If an instance
* of \Exception the exception message will be used and code will be set
* in params.
* @param array $options An array of options
* @return void
*/
public function set($message, array $options = []) {
$opts = array_merge($this->_defaultConfig, $options);
if ($message instanceof \Exception) {
$opts['params'] += ['code' => $message->getCode()];
$message = $message->getMessage();
}
@@ -111,12 +111,12 @@ public function testSet() {
public function testSetWithException() {
$this->assertNull($this->Session->read('Flash.flash'));
$this->Flash->set(new \Exception('This is a test message'));
$this->Flash->set(new \Exception('This is a test message', 404));
$expected = [
'message' => 'This is a test message',
'key' => 'flash',
'element' => null,
'params' => []
'params' => ['code' => 404]
];
$result = $this->Session->read('Flash.flash');
$this->assertEquals($expected, $result);

0 comments on commit bfe0db5

Please sign in to comment.
You can’t perform that action at this time.