Skip to content

Commit 5af3055

Browse files
authored
[12.x] Add environment information to json output of schedule:list command (#57741)
* feat: add environment to json output of schedule:list * chore: actually make use of the display method to reduce duplicate code * fix: test command * wip
1 parent f5d5c5a commit 5af3055

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Illuminate/Console/Scheduling/ScheduleListCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ public function handle(Schedule $schedule)
6767

6868
$events = $this->sortEvents($events, $timezone);
6969

70-
$this->option('json')
71-
? $this->displayJson($events, $timezone)
72-
: $this->displayForCli($events, $timezone);
70+
$this->display($events, $timezone);
7371
}
7472

7573
/**
@@ -107,6 +105,7 @@ protected function displayJson(Collection $events, DateTimeZone $timezone)
107105
'timezone' => $timezone->getName(),
108106
'has_mutex' => $event->mutex->exists($event),
109107
'repeat_seconds' => $event->isRepeatable() ? $event->repeatSeconds : null,
108+
'environments' => $event->environments,
110109
];
111110
})->values()->toJson());
112111
}

tests/Integration/Console/Scheduling/ScheduleListCommandTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public function testDisplayScheduleAsJson()
103103
$this->assertStringContainsString('2023-04-01 00:00:00', $data[0]['next_due_date']);
104104
$this->assertSame('3 months from now', $data[0]['next_due_date_human']);
105105
$this->assertFalse($data[0]['has_mutex']);
106+
$this->assertIsArray($data[0]['environments']);
107+
$this->assertEmpty($data[0]['environments']);
106108

107109
$this->assertSame('* * * * *', $data[2]['expression']);
108110
$this->assertSame('php artisan foobar a='.ProcessUtils::escapeArgument('b'), $data[2]['command']);
@@ -117,6 +119,24 @@ public function testDisplayScheduleAsJson()
117119
$this->assertStringContainsString('ScheduleListCommandTest.php', $data[8]['command']);
118120
}
119121

122+
public function testDisplayScheduleAsJsonWithSpecificEnvironment()
123+
{
124+
$environment = 'production';
125+
$this->schedule->command(FooCommand::class)->quarterly()->environments($environment);
126+
127+
$this->withoutMockingConsoleOutput()->artisan(ScheduleListCommand::class, ['--json' => true]);
128+
$output = Artisan::output();
129+
130+
$this->assertJson($output);
131+
$data = json_decode($output, true);
132+
$this->assertIsArray($data);
133+
$this->assertCount(1, $data);
134+
135+
$this->assertIsArray($data[0]['environments']);
136+
$this->assertNotEmpty($data[0]['environments']);
137+
$this->assertContains($environment, $data[0]['environments']);
138+
}
139+
120140
public function testDisplayScheduleWithSortAsJson()
121141
{
122142
$this->schedule->command(FooCommand::class)->quarterly();

0 commit comments

Comments
 (0)