Skip to content

Commit

Permalink
allow plain boolean into when and skip
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jul 20, 2017
1 parent 9e65194 commit 1d1a96e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,25 +532,29 @@ public function withoutOverlapping()
/**
* Register a callback to further filter the schedule.
*
* @param \Closure $callback
* @param \Closure|boolean $callback
* @return $this
*/
public function when(Closure $callback)
public function when($callback)
{
$this->filters[] = $callback;
$this->filters[] = is_callable($callback) ? $callback : function () use ($callback) {
return $callback;
};

return $this;
}

/**
* Register a callback to further filter the schedule.
*
* @param \Closure $callback
* @param \Closure|boolean $callback
* @return $this
*/
public function skip(Closure $callback)
public function skip($callback)
{
$this->rejects[] = $callback;
$this->rejects[] = is_callable($callback) ? $callback : function () use ($callback) {
return $callback;
};

return $this;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Console/ConsoleScheduledEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function testBasicCronCompilation()
return false;
})->filtersPass($app));

$event = new Event(m::mock('Illuminate\Console\Scheduling\Mutex'), 'php foo');
$this->assertEquals('* * * * * *', $event->getExpression());
$this->assertFalse($event->when(false)->filtersPass($app));

// chained rules should be commutative
$eventA = new Event(m::mock('Illuminate\Console\Scheduling\Mutex'), 'php foo');
$eventB = new Event(m::mock('Illuminate\Console\Scheduling\Mutex'), 'php foo');
Expand Down

0 comments on commit 1d1a96e

Please sign in to comment.