diff --git a/src/Illuminate/Console/Scheduling/Event.php b/src/Illuminate/Console/Scheduling/Event.php index 63ac6510e1fc..f1aa70da4084 100644 --- a/src/Illuminate/Console/Scheduling/Event.php +++ b/src/Illuminate/Console/Scheduling/Event.php @@ -532,12 +532,14 @@ 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; } @@ -545,12 +547,14 @@ public function when(Closure $callback) /** * 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; } diff --git a/tests/Console/ConsoleScheduledEventTest.php b/tests/Console/ConsoleScheduledEventTest.php index f12f0b7f8262..7fe250ce4dc4 100644 --- a/tests/Console/ConsoleScheduledEventTest.php +++ b/tests/Console/ConsoleScheduledEventTest.php @@ -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');