Skip to content

Commit

Permalink
Fix events return false
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dansleboby committed Feb 2, 2020
1 parent 046a0b5 commit 2402167
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Darryldecode/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
40 changes: 20 additions & 20 deletions tests/CartTestEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2402167

Please sign in to comment.