1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
<?php
namespace Illuminate\Tests\Integration\Foundation\Console;
use Illuminate\Foundation\Console\ClosureCommand;
use Illuminate\Support\ServiceProvider;
use Illuminate\Tests\Integration\Generators\TestCase;
use Orchestra\Testbench\Concerns\InteractsWithPublishedFiles;
class OptimizeCommandTest extends TestCase
{
use InteractsWithPublishedFiles;
protected $files = [
'bootstrap/cache/config.php',
'bootstrap/cache/events.php',
];
protected function getPackageProviders($app): array
{
return [ServiceProviderWithOptimize::class];
}
public function testCanListenToOptimizingEvent(): void
{
$this->withoutDeprecationHandling();
$this->artisan('optimize')
->assertSuccessful()
->expectsOutputToContain('my package');
}
public function testCanExcludeCommandsByKey(): void
{
$this->artisan('optimize', ['--except' => 'my package'])
->assertSuccessful()
->doesntExpectOutputToContain('my package');
}
public function testCanExcludeCommandsByCommand(): void
{
$this->artisan('optimize', ['--except' => 'my_package:cache'])
->assertSuccessful()
->doesntExpectOutputToContain('my_package:cache');
}
}
class ServiceProviderWithOptimize extends ServiceProvider
{
public function boot(): void
{
$this->commands([
new ClosureCommand('my_package:cache', fn () => 0),
]);
$this->optimizes(
optimize: 'my_package:cache',
key: 'my package',
);
}
}
|