Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ public function group(Closure $events)
throw new RuntimeException('Invoke an attribute method such as Schedule::daily() before defining a schedule group.');
}

$this->groupStack[] = clone $this->attributes;
$this->groupStack[] = $this->attributes;
$this->attributes = null;

$events($this);

Expand All @@ -327,17 +328,17 @@ public function group(Closure $events)
*/
protected function mergePendingAttributes(Event $event)
{
if (isset($this->attributes)) {
$this->attributes->mergeAttributes($event);

$this->attributes = null;
}

if (! empty($this->groupStack)) {
$group = array_last($this->groupStack);

$group->mergeAttributes($event);
}

if (isset($this->attributes)) {
$this->attributes->mergeAttributes($event);

$this->attributes = null;
}
}

/**
Expand Down Expand Up @@ -476,7 +477,7 @@ public function __call($method, $parameters)
}

if (method_exists(PendingEventAttributes::class, $method)) {
$this->attributes ??= array_last($this->groupStack) ?: new PendingEventAttributes($this);
$this->attributes ??= $this->groupStack ? clone array_last($this->groupStack) : new PendingEventAttributes($this);

return $this->attributes->$method(...$parameters);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Integration/Console/Scheduling/ScheduleGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,19 @@ public static function scheduleTestCases()
],
];
}

public function testGroupedPendingEventAttribute()
{
$schedule = new ScheduleClass;
$schedule->weekdays()->group(function ($schedule) {
$schedule->command('inspire')->at('00:00'); // this is event, not pending attribute
$schedule->at('01:00')->command('inspire'); // this is pending attribute
$schedule->command('inspire'); // this goes back to group pending attribute
});

$events = $schedule->events();
$this->assertSame('0 0 * * 1-5', $events[0]->expression);
$this->assertSame('0 1 * * 1-5', $events[1]->expression);
$this->assertSame('* * * * 1-5', $events[2]->expression);
}
}
Loading