From 24021674ce00848aafac94f77fdd6b8fc63689c3 Mon Sep 17 00:00:00 2001 From: gilbert1995 Date: Sun, 2 Feb 2020 00:15:39 -0500 Subject: [PATCH] Fix events return false The event listener when it return false was not considered because the halt on dispatch was false and it return an empty array, with halt true we get the right return --- src/Darryldecode/Cart/Cart.php | 2 +- tests/CartTestEvents.php | 40 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index e2838c7..d8fdf7d 100644 --- a/src/Darryldecode/Cart/Cart.php +++ b/src/Darryldecode/Cart/Cart.php @@ -849,7 +849,7 @@ public function setThousandsSep($thousands_sep) */ protected function fireEvent($name, $value = []) { - return $this->events->dispatch($this->getInstanceName() . '.' . $name, array_values([$value, $this])); + return $this->events->dispatch($this->getInstanceName() . '.' . $name, array_values([$value, $this]), true); } /** diff --git a/tests/CartTestEvents.php b/tests/CartTestEvents.php index 6ec0184..1f162a4 100644 --- a/tests/CartTestEvents.php +++ b/tests/CartTestEvents.php @@ -27,7 +27,7 @@ public function tearDown(): void public function test_event_cart_created() { $events = m::mock('Illuminate\Contracts\Events\Dispatcher'); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array')); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true); $cart = new Cart( new SessionMock(), @@ -43,9 +43,9 @@ public function test_event_cart_created() public function test_event_cart_adding() { $events = m::mock('Illuminate\Events\Dispatcher'); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array')); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.adding', m::type('array')); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.added', m::type('array')); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true); $cart = new Cart( new SessionMock(), @@ -63,9 +63,9 @@ public function test_event_cart_adding() public function test_event_cart_adding_multiple_times() { $events = m::mock('Illuminate\Events\Dispatcher'); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array')); - $events->shouldReceive('dispatch')->times(2)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array')); - $events->shouldReceive('dispatch')->times(2)->with(self::CART_INSTANCE_NAME.'.added', m::type('array')); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true); + $events->shouldReceive('dispatch')->times(2)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true); + $events->shouldReceive('dispatch')->times(2)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true); $cart = new Cart( new SessionMock(), @@ -84,9 +84,9 @@ public function test_event_cart_adding_multiple_times() public function test_event_cart_adding_multiple_times_scenario_two() { $events = m::mock('Illuminate\Events\Dispatcher'); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array')); - $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array')); - $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array')); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true); + $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true); + $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true); $items = array( array( @@ -128,11 +128,11 @@ public function test_event_cart_adding_multiple_times_scenario_two() public function test_event_cart_remove_item() { $events = m::mock('Illuminate\Events\Dispatcher'); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array')); - $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array')); - $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array')); - $events->shouldReceive('dispatch')->times(1)->with(self::CART_INSTANCE_NAME.'.removing', m::type('array')); - $events->shouldReceive('dispatch')->times(1)->with(self::CART_INSTANCE_NAME.'.removed', m::type('array')); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true); + $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true); + $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true); + $events->shouldReceive('dispatch')->times(1)->with(self::CART_INSTANCE_NAME.'.removing', m::type('array'), true); + $events->shouldReceive('dispatch')->times(1)->with(self::CART_INSTANCE_NAME.'.removed', m::type('array'), true); $items = array( array( @@ -176,11 +176,11 @@ public function test_event_cart_remove_item() public function test_event_cart_clear() { $events = m::mock('Illuminate\Events\Dispatcher'); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array')); - $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array')); - $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array')); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.clearing', m::type('array')); - $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.cleared', m::type('array')); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true); + $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true); + $events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.clearing', m::type('array'), true); + $events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.cleared', m::type('array'), true); $items = array( array(