Drop carbon, use chronos

This commit is contained in:
Dane Everitt 2018-08-31 20:52:15 -07:00
parent f3efe546da
commit e5636405f3
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 11 additions and 34 deletions

View file

@ -9,7 +9,7 @@
namespace Pterodactyl\Console\Commands\Schedule;
use Carbon\Carbon;
use Cake\Chronos\Chronos;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Pterodactyl\Services\Schedules\ProcessScheduleService;
@ -17,11 +17,6 @@ use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
class ProcessRunnableCommand extends Command
{
/**
* @var \Carbon\Carbon
*/
protected $carbon;
/**
* @var string
*/
@ -45,31 +40,23 @@ class ProcessRunnableCommand extends Command
/**
* ProcessRunnableCommand constructor.
*
* @param \Carbon\Carbon $carbon
* @param \Pterodactyl\Services\Schedules\ProcessScheduleService $processScheduleService
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
*/
public function __construct(
Carbon $carbon,
ProcessScheduleService $processScheduleService,
ScheduleRepositoryInterface $repository
) {
public function __construct(ProcessScheduleService $processScheduleService, ScheduleRepositoryInterface $repository)
{
parent::__construct();
$this->carbon = $carbon;
$this->processScheduleService = $processScheduleService;
$this->repository = $repository;
}
/**
* Handle command execution.
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle()
{
$schedules = $this->repository->getSchedulesToProcess($this->carbon->now()->toAtomString());
$schedules = $this->repository->getSchedulesToProcess(Chronos::now()->toAtomString());
$bar = $this->output->createProgressBar(count($schedules));
$schedules->each(function ($schedule) use ($bar) {

View file

@ -10,7 +10,7 @@
namespace Tests\Unit\Commands\Schedule;
use Mockery as m;
use Carbon\Carbon;
use Cake\Chronos\Chronos;
use Pterodactyl\Models\Task;
use Pterodactyl\Models\Schedule;
use Tests\Unit\Commands\CommandTestCase;
@ -20,11 +20,6 @@ use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
class ProcessRunnableCommandTest extends CommandTestCase
{
/**
* @var \Carbon\Carbon
*/
protected $carbon;
/**
* @var \Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand
*/
@ -47,11 +42,12 @@ class ProcessRunnableCommandTest extends CommandTestCase
{
parent::setUp();
$this->carbon = m::mock(Carbon::class);
Chronos::setTestNow(Chronos::now());
$this->processScheduleService = m::mock(ProcessScheduleService::class);
$this->repository = m::mock(ScheduleRepositoryInterface::class);
$this->command = new ProcessRunnableCommand($this->carbon, $this->processScheduleService, $this->repository);
$this->command = new ProcessRunnableCommand($this->processScheduleService, $this->repository);
}
/**
@ -62,9 +58,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
$schedule = factory(Schedule::class)->make();
$schedule->tasks = collect([factory(Task::class)->make()]);
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
$this->processScheduleService->shouldReceive('handle')->with($schedule)->once()->andReturnNull();
$display = $this->runCommand($this->command);
@ -84,9 +78,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
$schedule = factory(Schedule::class)->make();
$schedule->tasks = collect([]);
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
$display = $this->runCommand($this->command);
@ -104,9 +96,7 @@ class ProcessRunnableCommandTest extends CommandTestCase
{
$schedule = factory(Schedule::class)->make(['tasks' => null]);
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
$display = $this->runCommand($this->command);