Skip to content

Commit

Permalink
[11.x] Simplify ApplicationBuilder::withSchedule() (#50765)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
crynobone and StyleCIBot authored Mar 26, 2024
1 parent 5daf210 commit 5c0ad50
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ public function testRunUsingChoices()
)
->expectsOutputToContain('Running [callback]');
}

protected function tearDown(): void
{
parent::tearDown();

Carbon::setTestNow(null);
}
}

class BarCommandStub extends Command
Expand Down
41 changes: 41 additions & 0 deletions tests/Integration/Foundation/Configuration/WithScheduleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Illuminate\Tests\Integration\Foundation\Configuration;

use Illuminate\Console\Scheduling\ScheduleListCommand;
use Illuminate\Foundation\Application;
use Illuminate\Support\Carbon;
use Orchestra\Testbench\TestCase;

class WithScheduleTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();

Carbon::setTestNow('2023-01-01');
ScheduleListCommand::resolveTerminalWidthUsing(fn () => 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');
}
}

0 comments on commit 5c0ad50

Please sign in to comment.