Skip to content

Commit 2402167

Browse files
committed
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
1 parent 046a0b5 commit 2402167

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/Darryldecode/Cart/Cart.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ public function setThousandsSep($thousands_sep)
849849
*/
850850
protected function fireEvent($name, $value = [])
851851
{
852-
return $this->events->dispatch($this->getInstanceName() . '.' . $name, array_values([$value, $this]));
852+
return $this->events->dispatch($this->getInstanceName() . '.' . $name, array_values([$value, $this]), true);
853853
}
854854

855855
/**

tests/CartTestEvents.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function tearDown(): void
2727
public function test_event_cart_created()
2828
{
2929
$events = m::mock('Illuminate\Contracts\Events\Dispatcher');
30-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'));
30+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true);
3131

3232
$cart = new Cart(
3333
new SessionMock(),
@@ -43,9 +43,9 @@ public function test_event_cart_created()
4343
public function test_event_cart_adding()
4444
{
4545
$events = m::mock('Illuminate\Events\Dispatcher');
46-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'));
47-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'));
48-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.added', m::type('array'));
46+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true);
47+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true);
48+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true);
4949

5050
$cart = new Cart(
5151
new SessionMock(),
@@ -63,9 +63,9 @@ public function test_event_cart_adding()
6363
public function test_event_cart_adding_multiple_times()
6464
{
6565
$events = m::mock('Illuminate\Events\Dispatcher');
66-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'));
67-
$events->shouldReceive('dispatch')->times(2)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'));
68-
$events->shouldReceive('dispatch')->times(2)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'));
66+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true);
67+
$events->shouldReceive('dispatch')->times(2)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true);
68+
$events->shouldReceive('dispatch')->times(2)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true);
6969

7070
$cart = new Cart(
7171
new SessionMock(),
@@ -84,9 +84,9 @@ public function test_event_cart_adding_multiple_times()
8484
public function test_event_cart_adding_multiple_times_scenario_two()
8585
{
8686
$events = m::mock('Illuminate\Events\Dispatcher');
87-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'));
88-
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'));
89-
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'));
87+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true);
88+
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true);
89+
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true);
9090

9191
$items = array(
9292
array(
@@ -128,11 +128,11 @@ public function test_event_cart_adding_multiple_times_scenario_two()
128128
public function test_event_cart_remove_item()
129129
{
130130
$events = m::mock('Illuminate\Events\Dispatcher');
131-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'));
132-
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'));
133-
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'));
134-
$events->shouldReceive('dispatch')->times(1)->with(self::CART_INSTANCE_NAME.'.removing', m::type('array'));
135-
$events->shouldReceive('dispatch')->times(1)->with(self::CART_INSTANCE_NAME.'.removed', m::type('array'));
131+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true);
132+
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true);
133+
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true);
134+
$events->shouldReceive('dispatch')->times(1)->with(self::CART_INSTANCE_NAME.'.removing', m::type('array'), true);
135+
$events->shouldReceive('dispatch')->times(1)->with(self::CART_INSTANCE_NAME.'.removed', m::type('array'), true);
136136

137137
$items = array(
138138
array(
@@ -176,11 +176,11 @@ public function test_event_cart_remove_item()
176176
public function test_event_cart_clear()
177177
{
178178
$events = m::mock('Illuminate\Events\Dispatcher');
179-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'));
180-
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'));
181-
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'));
182-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.clearing', m::type('array'));
183-
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.cleared', m::type('array'));
179+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.created', m::type('array'), true);
180+
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.adding', m::type('array'), true);
181+
$events->shouldReceive('dispatch')->times(3)->with(self::CART_INSTANCE_NAME.'.added', m::type('array'), true);
182+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.clearing', m::type('array'), true);
183+
$events->shouldReceive('dispatch')->once()->with(self::CART_INSTANCE_NAME.'.cleared', m::type('array'), true);
184184

185185
$items = array(
186186
array(

0 commit comments

Comments
 (0)