diff --git a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php index 9822eafabdeb..1138ab7ffa52 100644 --- a/src/Illuminate/Console/Scheduling/ScheduleListCommand.php +++ b/src/Illuminate/Console/Scheduling/ScheduleListCommand.php @@ -67,9 +67,7 @@ public function handle(Schedule $schedule) $events = $this->sortEvents($events, $timezone); - $this->option('json') - ? $this->displayJson($events, $timezone) - : $this->displayForCli($events, $timezone); + $this->display($events, $timezone); } /** @@ -107,6 +105,7 @@ protected function displayJson(Collection $events, DateTimeZone $timezone) 'timezone' => $timezone->getName(), 'has_mutex' => $event->mutex->exists($event), 'repeat_seconds' => $event->isRepeatable() ? $event->repeatSeconds : null, + 'environments' => $event->environments, ]; })->values()->toJson()); } diff --git a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php index 633288e1188a..582de917b6e4 100644 --- a/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleListCommandTest.php @@ -103,6 +103,8 @@ public function testDisplayScheduleAsJson() $this->assertStringContainsString('2023-04-01 00:00:00', $data[0]['next_due_date']); $this->assertSame('3 months from now', $data[0]['next_due_date_human']); $this->assertFalse($data[0]['has_mutex']); + $this->assertIsArray($data[0]['environments']); + $this->assertEmpty($data[0]['environments']); $this->assertSame('* * * * *', $data[2]['expression']); $this->assertSame('php artisan foobar a='.ProcessUtils::escapeArgument('b'), $data[2]['command']); @@ -117,6 +119,24 @@ public function testDisplayScheduleAsJson() $this->assertStringContainsString('ScheduleListCommandTest.php', $data[8]['command']); } + public function testDisplayScheduleAsJsonWithSpecificEnvironment() + { + $environment = 'production'; + $this->schedule->command(FooCommand::class)->quarterly()->environments($environment); + + $this->withoutMockingConsoleOutput()->artisan(ScheduleListCommand::class, ['--json' => true]); + $output = Artisan::output(); + + $this->assertJson($output); + $data = json_decode($output, true); + $this->assertIsArray($data); + $this->assertCount(1, $data); + + $this->assertIsArray($data[0]['environments']); + $this->assertNotEmpty($data[0]['environments']); + $this->assertContains($environment, $data[0]['environments']); + } + public function testDisplayScheduleWithSortAsJson() { $this->schedule->command(FooCommand::class)->quarterly();