From d8438ecf51e92591564609eb11d028d3af754880 Mon Sep 17 00:00:00 2001 From: Istiak Tridip <13367189+istiak-tridip@users.noreply.github.com> Date: Fri, 22 Nov 2024 04:30:42 +0600 Subject: [PATCH] [11.x] Fix attribute inheritance for nested scheduled groups (#53626) * fix nested group * refactor tests --- src/Illuminate/Console/Scheduling/Schedule.php | 2 +- .../Console/Scheduling/ScheduleGroupTest.php | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index c2b0e88663da..e22508690493 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -454,7 +454,7 @@ public function __call($method, $parameters) } if (method_exists(PendingEventAttributes::class, $method)) { - $this->attributes ??= new PendingEventAttributes($this); + $this->attributes ??= end($this->groupStack) ?: new PendingEventAttributes($this); return $this->attributes->$method(...$parameters); } diff --git a/tests/Integration/Console/Scheduling/ScheduleGroupTest.php b/tests/Integration/Console/Scheduling/ScheduleGroupTest.php index e0ca872663af..f74ee43e9404 100644 --- a/tests/Integration/Console/Scheduling/ScheduleGroupTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleGroupTest.php @@ -75,19 +75,14 @@ public function testGroupedScheduleCanBeNested() ->timezone('UTC') ->group(function () { Schedule::command('inspire'); - Schedule::timezone('Asia/Dhaka') - ->everyMinute() - ->group(function () { - Schedule::command('inspire'); - }); + Schedule::timezone('Asia/Dhaka')->group(function () { + Schedule::command('inspire'); + }); }); $events = Schedule::events(); $this->assertSame('UTC', $events[0]->timezone); - $this->assertSame('0 0 * * *', $events[0]->expression); - $this->assertSame('Asia/Dhaka', $events[1]->timezone); - $this->assertSame('* * * * *', $events[1]->expression); } #[DataProvider('groupAttributes')]