Skip to content

Commit e563640

Browse files
committed
Drop carbon, use chronos
1 parent f3efe54 commit e563640

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

app/Console/Commands/Schedule/ProcessRunnableCommand.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@
99

1010
namespace Pterodactyl\Console\Commands\Schedule;
1111

12-
use Carbon\Carbon;
12+
use Cake\Chronos\Chronos;
1313
use Illuminate\Console\Command;
1414
use Illuminate\Support\Collection;
1515
use Pterodactyl\Services\Schedules\ProcessScheduleService;
1616
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
1717

1818
class ProcessRunnableCommand extends Command
1919
{
20-
/**
21-
* @var \Carbon\Carbon
22-
*/
23-
protected $carbon;
24-
2520
/**
2621
* @var string
2722
*/
@@ -45,31 +40,23 @@ class ProcessRunnableCommand extends Command
4540
/**
4641
* ProcessRunnableCommand constructor.
4742
*
48-
* @param \Carbon\Carbon $carbon
4943
* @param \Pterodactyl\Services\Schedules\ProcessScheduleService $processScheduleService
5044
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
5145
*/
52-
public function __construct(
53-
Carbon $carbon,
54-
ProcessScheduleService $processScheduleService,
55-
ScheduleRepositoryInterface $repository
56-
) {
46+
public function __construct(ProcessScheduleService $processScheduleService, ScheduleRepositoryInterface $repository)
47+
{
5748
parent::__construct();
5849

59-
$this->carbon = $carbon;
6050
$this->processScheduleService = $processScheduleService;
6151
$this->repository = $repository;
6252
}
6353

6454
/**
6555
* Handle command execution.
66-
*
67-
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
68-
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
6956
*/
7057
public function handle()
7158
{
72-
$schedules = $this->repository->getSchedulesToProcess($this->carbon->now()->toAtomString());
59+
$schedules = $this->repository->getSchedulesToProcess(Chronos::now()->toAtomString());
7360

7461
$bar = $this->output->createProgressBar(count($schedules));
7562
$schedules->each(function ($schedule) use ($bar) {

tests/Unit/Commands/Schedule/ProcessRunnableCommandTest.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Tests\Unit\Commands\Schedule;
1111

1212
use Mockery as m;
13-
use Carbon\Carbon;
13+
use Cake\Chronos\Chronos;
1414
use Pterodactyl\Models\Task;
1515
use Pterodactyl\Models\Schedule;
1616
use Tests\Unit\Commands\CommandTestCase;
@@ -20,11 +20,6 @@
2020

2121
class ProcessRunnableCommandTest extends CommandTestCase
2222
{
23-
/**
24-
* @var \Carbon\Carbon
25-
*/
26-
protected $carbon;
27-
2823
/**
2924
* @var \Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand
3025
*/
@@ -47,11 +42,12 @@ public function setUp()
4742
{
4843
parent::setUp();
4944

50-
$this->carbon = m::mock(Carbon::class);
45+
Chronos::setTestNow(Chronos::now());
46+
5147
$this->processScheduleService = m::mock(ProcessScheduleService::class);
5248
$this->repository = m::mock(ScheduleRepositoryInterface::class);
5349

54-
$this->command = new ProcessRunnableCommand($this->carbon, $this->processScheduleService, $this->repository);
50+
$this->command = new ProcessRunnableCommand($this->processScheduleService, $this->repository);
5551
}
5652

5753
/**
@@ -62,9 +58,7 @@ public function testScheduleIsQueued()
6258
$schedule = factory(Schedule::class)->make();
6359
$schedule->tasks = collect([factory(Task::class)->make()]);
6460

65-
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
66-
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
67-
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
61+
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
6862
$this->processScheduleService->shouldReceive('handle')->with($schedule)->once()->andReturnNull();
6963

7064
$display = $this->runCommand($this->command);
@@ -84,9 +78,7 @@ public function testScheduleWithNoTasksIsNotProcessed()
8478
$schedule = factory(Schedule::class)->make();
8579
$schedule->tasks = collect([]);
8680

87-
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
88-
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
89-
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
81+
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
9082

9183
$display = $this->runCommand($this->command);
9284

@@ -104,9 +96,7 @@ public function testScheduleWithTasksObjectThatIsNotInstanceOfCollectionIsNotPro
10496
{
10597
$schedule = factory(Schedule::class)->make(['tasks' => null]);
10698

107-
$this->carbon->shouldReceive('now')->withNoArgs()->once()->andReturnSelf()
108-
->shouldReceive('toAtomString')->withNoArgs()->once()->andReturn('00:00:00');
109-
$this->repository->shouldReceive('getSchedulesToProcess')->with('00:00:00')->once()->andReturn(collect([$schedule]));
99+
$this->repository->shouldReceive('getSchedulesToProcess')->with(Chronos::now()->toAtomString())->once()->andReturn(collect([$schedule]));
110100

111101
$display = $this->runCommand($this->command);
112102

0 commit comments

Comments
 (0)