From e5636405f334a0be5b145d997693fbc6e360bb33 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 31 Aug 2018 20:52:15 -0700 Subject: [PATCH] Drop carbon, use chronos --- .../Schedule/ProcessRunnableCommand.php | 21 ++++------------ .../Schedule/ProcessRunnableCommandTest.php | 24 ++++++------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/app/Console/Commands/Schedule/ProcessRunnableCommand.php b/app/Console/Commands/Schedule/ProcessRunnableCommand.php index 88646c030..89e8fac8e 100644 --- a/app/Console/Commands/Schedule/ProcessRunnableCommand.php +++ b/app/Console/Commands/Schedule/ProcessRunnableCommand.php @@ -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) { diff --git a/tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php b/tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php index 24f53e4de..93ab0d1dd 100644 --- a/tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php +++ b/tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php @@ -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);