Skip to content

Commit

Permalink
Hotfix invalid job path (#36)
Browse files Browse the repository at this point in the history
* Fix #35

Throw exception if when scheduling a php job the path doesn't exist

* StyleCI fix

* StyleCI fix
  • Loading branch information
peppeocchi authored Oct 13, 2017
1 parent 0c8926e commit fe644ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/GO/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 24 additions & 0 deletions tests/GO/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fe644ed

Please sign in to comment.