Skip to content

Commit 262d1e3

Browse files
committed
Fix clear files logs schedule
1 parent 406306e commit 262d1e3

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/Laravel/LaravelServiceProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ public function boot(): void
6767
$config = self::getConfig($this->app);
6868
$this->passEventsToTelescopeHttpCatcher($config);
6969

70-
$clearAt = $config->getTimeForClearSchedule();
71-
72-
if ($clearAt !== null) {
73-
$schedule = $this->app->make(Schedule::class);
74-
assert($schedule instanceof Schedule);
75-
76-
$schedule->command(ClearFileLogsCommand::class)
70+
$this->callAfterResolving(Schedule::class, static function (Schedule $schedule) use ($config): void {
71+
$clearAt = $config->getTimeForClearSchedule();
72+
if ($clearAt === null) {
73+
return;
74+
}
75+
$schedule
76+
->command(ClearFileLogsCommand::class)
7777
->dailyAt($clearAt);
78-
}
78+
});
7979
}
8080

8181
/**

tests/Laravel/LaravelServiceProviderTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace WrkFlow\ApiSdkBuilderTests\Laravel;
66

7+
use Illuminate\Console\Scheduling\Schedule;
78
use WrkFlow\ApiSdkBuilder\Log\Constants\LoggerConstants;
89
use WrkFlow\ApiSdkBuilder\Log\Interfaces\ApiLoggerInterface;
910

@@ -17,4 +18,31 @@ public function testLoggerCanBeBuilt(): void
1718
}
1819
}
1920
}
21+
22+
public function testClearFilesLogsCommandRegistered(): void
23+
{
24+
$schedule = $this->app()
25+
->make(Schedule::class);
26+
assert($schedule instanceof Schedule);
27+
28+
$commands = [
29+
'api-sdk:logs:clear' => false,
30+
];
31+
32+
foreach ($schedule->events() as $event) {
33+
if ($event->command === null) {
34+
continue;
35+
}
36+
37+
foreach (array_keys($commands) as $command) {
38+
if (str_contains($event->command, $command)) {
39+
$commands[$command] = true;
40+
}
41+
}
42+
}
43+
44+
foreach ($commands as $command => $found) {
45+
$this->assertTrue($found, sprintf('Command %s not found in schedule', $command));
46+
}
47+
}
2048
}

0 commit comments

Comments
 (0)