From a24423031004b6b60e8a8c6ff3113ab0803bc596 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 12 Aug 2020 08:55:00 +0100 Subject: [PATCH] Fix defaultTimezone not respected in scheduled Events Co-Authored-By: Stephen Odoardi --- src/Illuminate/Console/Scheduling/CallbackEvent.php | 4 +++- src/Illuminate/Console/Scheduling/Schedule.php | 2 +- tests/Console/ConsoleEventSchedulerTest.php | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/CallbackEvent.php b/src/Illuminate/Console/Scheduling/CallbackEvent.php index 799c4afce7d3..96b1c1e1bfbd 100644 --- a/src/Illuminate/Console/Scheduling/CallbackEvent.php +++ b/src/Illuminate/Console/Scheduling/CallbackEvent.php @@ -28,11 +28,12 @@ class CallbackEvent extends Event * @param \Illuminate\Console\Scheduling\EventMutex $mutex * @param string $callback * @param array $parameters + * @param \DateTimeZone|string|null $timezone * @return void * * @throws \InvalidArgumentException */ - public function __construct(EventMutex $mutex, $callback, array $parameters = []) + public function __construct(EventMutex $mutex, $callback, array $parameters = [], $timezone = null) { if (! is_string($callback) && ! is_callable($callback)) { throw new InvalidArgumentException( @@ -43,6 +44,7 @@ public function __construct(EventMutex $mutex, $callback, array $parameters = [] $this->mutex = $mutex; $this->callback = $callback; $this->parameters = $parameters; + $this->timezone = $timezone; } /** diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index 0c4292d105b3..bfbb4141a6d6 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -91,7 +91,7 @@ public function __construct($timezone = null) public function call($callback, array $parameters = []) { $this->events[] = $event = new CallbackEvent( - $this->eventMutex, $callback, $parameters + $this->eventMutex, $callback, $parameters, $this->timezone ); return $event; diff --git a/tests/Console/ConsoleEventSchedulerTest.php b/tests/Console/ConsoleEventSchedulerTest.php index a45c4531206a..a04a95081946 100644 --- a/tests/Console/ConsoleEventSchedulerTest.php +++ b/tests/Console/ConsoleEventSchedulerTest.php @@ -117,6 +117,19 @@ public function testCreateNewArtisanCommandUsingCommandClass() $binary = $escape.PHP_BINARY.$escape; $this->assertEquals($binary.' artisan foo:bar --force', $events[0]->command); } + + public function testCallCreatesNewJobWithTimezone() + { + $schedule = new Schedule('UTC'); + $schedule->call('path/to/command'); + $events = $schedule->events(); + $this->assertSame('UTC', $events[0]->timezone); + + $schedule = new Schedule('Asia/Tokyo'); + $schedule->call('path/to/command'); + $events = $schedule->events(); + $this->assertSame('Asia/Tokyo', $events[0]->timezone); + } } class FooClassStub