Skip to content

Commit 5c0ad50

Browse files
[11.x] Simplify ApplicationBuilder::withSchedule() (#50765)
* Simplify `ApplicationBuilder::withSchedule()` Signed-off-by: Mior Muhammad Zaki <[email protected]> * Apply fixes from StyleCI * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: StyleCI Bot <[email protected]>
1 parent 5daf210 commit 5c0ad50

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

src/Illuminate/Foundation/Configuration/ApplicationBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ protected function withCommandRouting(array $paths)
290290
*/
291291
public function withSchedule(callable $callback)
292292
{
293-
$this->app->afterResolving(ConsoleKernel::class, function (ConsoleKernel $kernel) use ($callback) {
294-
Artisan::starting(fn () => $callback($this->app->make(Schedule::class)));
295-
});
293+
Artisan::starting(fn () => $callback($this->app->make(Schedule::class)));
296294

297295
return $this;
298296
}

tests/Integration/Console/Scheduling/ScheduleTestCommandTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ public function testRunUsingChoices()
7777
)
7878
->expectsOutputToContain('Running [callback]');
7979
}
80-
81-
protected function tearDown(): void
82-
{
83-
parent::tearDown();
84-
85-
Carbon::setTestNow(null);
86-
}
8780
}
8881

8982
class BarCommandStub extends Command
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Foundation\Configuration;
4+
5+
use Illuminate\Console\Scheduling\ScheduleListCommand;
6+
use Illuminate\Foundation\Application;
7+
use Illuminate\Support\Carbon;
8+
use Orchestra\Testbench\TestCase;
9+
10+
class WithScheduleTest extends TestCase
11+
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
16+
Carbon::setTestNow('2023-01-01');
17+
ScheduleListCommand::resolveTerminalWidthUsing(fn () => 80);
18+
}
19+
20+
protected function tearDown(): void
21+
{
22+
ScheduleListCommand::resolveTerminalWidthUsing(null);
23+
24+
parent::tearDown();
25+
}
26+
27+
protected function resolveApplication()
28+
{
29+
return Application::configure(static::applicationBasePath())
30+
->withSchedule(function ($schedule) {
31+
$schedule->command('schedule:clear-cache')->everyMinute();
32+
})->create();
33+
}
34+
35+
public function testDisplaySchedule()
36+
{
37+
$this->artisan(ScheduleListCommand::class)
38+
->assertSuccessful()
39+
->expectsOutputToContain(' * * * * * php artisan schedule:clear-cache');
40+
}
41+
}

0 commit comments

Comments
 (0)