From 351c90e67f69fba5fa8a593176edf22de6d34de6 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 26 Mar 2024 11:50:55 +0800 Subject: [PATCH 1/3] Simplify `ApplicationBuilder::withSchedule()` Signed-off-by: Mior Muhammad Zaki --- .../Scheduling/ScheduleTestCommandTest.php | 7 ---- .../Configuration/WithScheduleTest.php | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 tests/Integration/Foundation/Configuration/WithScheduleTest.php diff --git a/tests/Integration/Console/Scheduling/ScheduleTestCommandTest.php b/tests/Integration/Console/Scheduling/ScheduleTestCommandTest.php index cde9883d8242..830fb0be5f79 100644 --- a/tests/Integration/Console/Scheduling/ScheduleTestCommandTest.php +++ b/tests/Integration/Console/Scheduling/ScheduleTestCommandTest.php @@ -77,13 +77,6 @@ public function testRunUsingChoices() ) ->expectsOutputToContain('Running [callback]'); } - - protected function tearDown(): void - { - parent::tearDown(); - - Carbon::setTestNow(null); - } } class BarCommandStub extends Command diff --git a/tests/Integration/Foundation/Configuration/WithScheduleTest.php b/tests/Integration/Foundation/Configuration/WithScheduleTest.php new file mode 100644 index 000000000000..a38789ed190c --- /dev/null +++ b/tests/Integration/Foundation/Configuration/WithScheduleTest.php @@ -0,0 +1,42 @@ + 80); + } + + protected function tearDown(): void + { + ScheduleListCommand::resolveTerminalWidthUsing(null); + + parent::tearDown(); + } + + protected function resolveApplication() + { + return Application::configure(static::applicationBasePath()) + ->withSchedule(function ($schedule) { + $schedule->command('schedule:clear-cache')->everyMinute(); + })->create(); + } + + public function testDisplaySchedule() + { + $this->artisan(ScheduleListCommand::class) + ->assertSuccessful() + ->expectsOutputToContain(' * * * * * php artisan schedule:clear-cache'); + } +} From 9cff0e461f7696669af6da7af7abe9ede092f6c5 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 26 Mar 2024 03:52:29 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- tests/Integration/Foundation/Configuration/WithScheduleTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/Foundation/Configuration/WithScheduleTest.php b/tests/Integration/Foundation/Configuration/WithScheduleTest.php index a38789ed190c..767727f233be 100644 --- a/tests/Integration/Foundation/Configuration/WithScheduleTest.php +++ b/tests/Integration/Foundation/Configuration/WithScheduleTest.php @@ -2,7 +2,6 @@ namespace Illuminate\Tests\Integration\Foundation\Configuration; -use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\ScheduleListCommand; use Illuminate\Foundation\Application; use Illuminate\Support\Carbon; From 47f9e1b5fd9f1802eeb8e65529fe3b7404ac28eb Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 26 Mar 2024 11:53:09 +0800 Subject: [PATCH 3/3] wip Signed-off-by: Mior Muhammad Zaki --- .../Foundation/Configuration/ApplicationBuilder.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php index 0e8f1913eb51..4f4469fe832a 100644 --- a/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php +++ b/src/Illuminate/Foundation/Configuration/ApplicationBuilder.php @@ -290,9 +290,7 @@ protected function withCommandRouting(array $paths) */ public function withSchedule(callable $callback) { - $this->app->afterResolving(ConsoleKernel::class, function (ConsoleKernel $kernel) use ($callback) { - Artisan::starting(fn () => $callback($this->app->make(Schedule::class))); - }); + Artisan::starting(fn () => $callback($this->app->make(Schedule::class))); return $this; }