From 825ed2ff2f878a188453f2374fe22ba9aed41236 Mon Sep 17 00:00:00 2001 From: crynobone Date: Fri, 14 Nov 2014 11:42:23 +0800 Subject: [PATCH] Use pull instead get and forget. Signed-off-by: crynobone --- src/Messages/MessageBag.php | 4 +--- tests/MessageBagTest.php | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Messages/MessageBag.php b/src/Messages/MessageBag.php index 6ce53fd..cf00227 100644 --- a/src/Messages/MessageBag.php +++ b/src/Messages/MessageBag.php @@ -73,11 +73,9 @@ public function retrieve() $this->instance->setSessionStore($this->session); if ($this->session->has('message')) { - $messages = @unserialize($this->session->get('message', '')); + $messages = unserialize($this->session->pull('message')); } - $this->session->forget('message'); - if (is_array($messages)) { $this->instance->merge($messages); } diff --git a/tests/MessageBagTest.php b/tests/MessageBagTest.php index 2264981..fb1b089 100644 --- a/tests/MessageBagTest.php +++ b/tests/MessageBagTest.php @@ -85,9 +85,8 @@ public function testRetrieveMethod() { $session = m::mock('\Illuminate\Session\Store'); $session->shouldReceive('has')->once()->andReturn(true) - ->shouldReceive('get')->once() - ->andReturn('a:2:{s:5:"hello";a:1:{i:0;s:8:"Hi World";}s:3:"bye";a:1:{i:0;s:7:"Goodbye";}}') - ->shouldReceive('forget')->once()->andReturn(true); + ->shouldReceive('pull')->once() + ->andReturn('a:2:{s:5:"hello";a:1:{i:0;s:8:"Hi World";}s:3:"bye";a:1:{i:0;s:7:"Goodbye";}}'); $retrieve = (new MessageBag)->setSessionStore($session)->retrieve(); $retrieve->setFormat(); @@ -107,9 +106,8 @@ public function testExtendMethod() { $session = m::mock('\Illuminate\Session\Store'); $session->shouldReceive('has')->once()->andReturn(true) - ->shouldReceive('get')->once() - ->andReturn('a:1:{s:5:"hello";a:1:{i:0;s:8:"Hi World";}}') - ->shouldReceive('forget')->once()->andReturn(true); + ->shouldReceive('pull')->once() + ->andReturn('a:1:{s:5:"hello";a:1:{i:0;s:8:"Hi World";}}'); $callback = function ($msg) { $msg->add('hello', 'Hi Orchestra Platform');