Add tests for schedule stuff

This commit is contained in:
Dane Everitt 2017-09-14 23:02:31 -05:00
parent a8c4d6afdb
commit 4e5398fb6b
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 424 additions and 5 deletions

View file

@ -77,7 +77,7 @@ class ScheduleCreationService
*/
public function handle($server, array $data, array $tasks = [])
{
Assert::true(($server instanceof Server || is_numeric($server)),
Assert::true(($server instanceof Server || is_digit($server)),
'First argument passed to handle must be numeric or instance of \Pterodactyl\Models\Server, received %s.'
);

View file

@ -59,17 +59,16 @@ class TaskCreationService
*/
public function handle($schedule, array $data, $returnModel = true)
{
Assert::true(($schedule instanceof Schedule || is_numeric($schedule)),
Assert::true(($schedule instanceof Schedule || is_digit($schedule)),
'First argument passed to handle must be numeric or instance of \Pterodactyl\Models\Schedule, received %s.'
);
$schedule = ($schedule instanceof Schedule) ? $schedule->id : $schedule;
if ($data['time_interval'] === 'm' && $data['time_value'] > 15) {
$delay = $data['time_interval'] === 'm' ? $data['time_value'] * 60 : $data['time_value'];
if ($delay > 900) {
throw new TaskIntervalTooLongException(trans('exceptions.tasks.chain_interval_too_long'));
}
$delay = $data['time_interval'] === 'm' ? $data['time_value'] * 60 : $data['time_value'];
$repository = ($returnModel) ? $this->repository : $this->repository->withoutFresh();
$task = $repository->create([
'schedule_id' => $schedule,

View file

@ -45,3 +45,17 @@ if (! function_exists('human_readable')) {
return app('file')->humanReadableSize($path, $precision);
}
}
if (! function_exists('is_digit')) {
/**
* Deal with normal (and irritating) PHP behavior to determine if
* a value is a non-float positive integer.
*
* @param mixed $value
* @return bool
*/
function is_digit($value)
{
return is_bool($value) ? false : ctype_digit(strval($value));
}
}