diff --git a/src/GO/Scheduler.php b/src/GO/Scheduler.php index 53eb07a..5e2e2b0 100644 --- a/src/GO/Scheduler.php +++ b/src/GO/Scheduler.php @@ -119,6 +119,10 @@ public function call(callable $fn, $args = [], $id = null) */ public function php($script, $bin = null, $args = [], $id = null) { + if (! is_string($script) || ! file_exists($script)) { + throw new InvalidArgumentException('The script should be a valid path to a file.'); + } + $bin = $bin !== null && is_string($bin) && file_exists($bin) ? $bin : (PHP_BINARY === '' ? '/usr/bin/php' : PHP_BINARY); diff --git a/tests/GO/SchedulerTest.php b/tests/GO/SchedulerTest.php index 731cfd0..70e2398 100644 --- a/tests/GO/SchedulerTest.php +++ b/tests/GO/SchedulerTest.php @@ -30,6 +30,30 @@ public function testShouldQueueAPhpScript() $this->assertEquals(count($scheduler->getQueuedJobs()), 1); } + /** + * @expectedException InvalidArgumentException + */ + public function testShouldThrowExceptionIfScriptIsNotAString() + { + $scheduler = new Scheduler(); + $scheduler->php(function () { + return false; + }); + + $scheduler->run(); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testShouldThrowExceptionIfScriptPathIsInvalid() + { + $scheduler = new Scheduler(); + $scheduler->php('someInvalidPathToAScript'); + + $scheduler->run(); + } + public function testShouldQueueAShellCommand() { $scheduler = new Scheduler();