Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Simplify ApplicationBuilder::withSchedule() #50765

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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');
}
}