55use Mockery as m ;
66use Tests \TestCase ;
77use Cron \CronExpression ;
8- use Cake \Chronos \Chronos ;
98use Pterodactyl \Models \Task ;
109use Pterodactyl \Models \Schedule ;
1110use Illuminate \Contracts \Bus \Dispatcher ;
@@ -38,7 +37,6 @@ public function setUp()
3837 {
3938 parent ::setUp ();
4039
41- Chronos::setTestNow (Chronos::now ());
4240 $ this ->dispatcher = m::mock (Dispatcher::class);
4341 $ this ->scheduleRepository = m::mock (ScheduleRepositoryInterface::class);
4442 $ this ->taskRepository = m::mock (TaskRepositoryInterface::class);
@@ -59,7 +57,7 @@ public function testScheduleIsUpdatedAndRun()
5957 $ formatted = sprintf ('%s %s %s * %s ' , $ model ->cron_minute , $ model ->cron_hour , $ model ->cron_day_of_month , $ model ->cron_day_of_week );
6058 $ this ->scheduleRepository ->shouldReceive ('update ' )->with ($ model ->id , [
6159 'is_processing ' => true ,
62- 'next_run_at ' => Chronos:: parse ( CronExpression::factory ($ formatted )->getNextRunDate ()-> format (Chronos:: ATOM ) ),
60+ 'next_run_at ' => CronExpression::factory ($ formatted )->getNextRunDate (),
6361 ]);
6462
6563 $ this ->taskRepository ->shouldReceive ('update ' )->with ($ task ->id , ['is_queued ' => true ])->once ();
@@ -77,35 +75,11 @@ public function testScheduleIsUpdatedAndRun()
7775 $ this ->assertTrue (true );
7876 }
7977
80- public function testScheduleRunTimeCanBeOverridden ()
81- {
82- $ model = factory (Schedule::class)->make ();
83- $ model ->setRelation ('tasks ' , collect ([$ task = factory (Task::class)->make ([
84- 'sequence_id ' => 1 ,
85- ])]));
86-
87- $ this ->scheduleRepository ->shouldReceive ('loadTasks ' )->with ($ model )->once ()->andReturn ($ model );
88-
89- $ this ->scheduleRepository ->shouldReceive ('update ' )->with ($ model ->id , [
90- 'is_processing ' => true ,
91- 'next_run_at ' => Chronos::now ()->addSeconds (15 ),
92- ]);
93-
94- $ this ->taskRepository ->shouldReceive ('update ' )->with ($ task ->id , ['is_queued ' => true ])->once ();
95-
96- $ this ->dispatcher ->shouldReceive ('dispatch ' )->with (m::on (function ($ class ) use ($ model , $ task ) {
97- $ this ->assertInstanceOf (RunTaskJob::class, $ class );
98- $ this ->assertSame ($ task ->time_offset , $ class ->delay );
99- $ this ->assertSame ($ task ->id , $ class ->task );
100- $ this ->assertSame ($ model ->id , $ class ->schedule );
101-
102- return true ;
103- }))->once ();
104-
105- $ this ->getService ()->setRunTimeOverride (Chronos::now ()->addSeconds (15 ))->handle ($ model );
106- $ this ->assertTrue (true );
107- }
108-
78+ /**
79+ * Return an instance of the service for testing purposes.
80+ *
81+ * @return \Pterodactyl\Services\Schedules\ProcessScheduleService
82+ */
10983 private function getService (): ProcessScheduleService
11084 {
11185 return new ProcessScheduleService ($ this ->dispatcher , $ this ->scheduleRepository , $ this ->taskRepository );
0 commit comments