Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mozex committed Mar 14, 2024
1 parent 264615f commit fb8283e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/ModulesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,12 @@ protected function bootRoutes(): void
);

$this->callAfterResolving(Kernel::class, function (Kernel $kernel) use ($commands) {
$kernel->addCommandRoutePaths(
$commands->pluck('path')->all()
);
// Compatibility with Laravel 10
if (method_exists($kernel, 'addCommandRoutePaths')) {
$kernel->addCommandRoutePaths(
$commands->pluck('path')->all()
);
}
});

$routes->each(function (array $asset): void {
Expand Down
9 changes: 6 additions & 3 deletions tests/Feature/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Modules\Second\Console\Commands\SecondValidCommand;
use Mozex\Modules\Enums\AssetType;
use Mozex\Modules\Scouts\CommandsScout;
use Mozex\Modules\Tests\Kernel;

test('scout will not collect when disabled', function () {
config()->set(
Expand Down Expand Up @@ -65,9 +66,11 @@
expect($commands)->toContain((new $asset['namespace'])->getName());
});

expect($commands)
->toContain('first:console-command-1')
->toContain('second:console-command-1');
if (method_exists(Kernel::class, 'addCommandRoutePaths')) {
expect($commands)
->toContain('first:console-command-1')
->toContain('second:console-command-1');
}

if ($cache) {
$discoverer->clear();
Expand Down
17 changes: 11 additions & 6 deletions tests/Feature/SchedulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Modules\Second\Console\WrongKernel;
use Mozex\Modules\Enums\AssetType;
use Mozex\Modules\Scouts\SchedulesScout;
use Mozex\Modules\Tests\Kernel;

test('scout will not collect when disabled', function () {
config()->set(
Expand Down Expand Up @@ -66,14 +67,18 @@
->toArray();

expect($schedules)
->toContain('first:console-command-1')
->toContain('first-scheduled-command-1')
->toContain('first-scheduled-command-2')
->toContain('first-scheduled-command-3')
->toContain('second:console-command-1')
->toContain('second-scheduled-command-1')
->toContain('second-scheduled-command-2')
->toContain('second-scheduled-command-3');
->toContain('second-scheduled-command-2');

if (method_exists(Kernel::class, 'addCommandRoutePaths')) {
expect($schedules)
->toContain('first:console-command-1')
->toContain('first-scheduled-command-2')
->toContain('first-scheduled-command-3')
->toContain('second:console-command-1')
->toContain('second-scheduled-command-3');
}

if ($cache) {
$discoverer->clear();
Expand Down

0 comments on commit fb8283e

Please sign in to comment.