|
8 | 8 | use Illuminate\Contracts\Foundation\Application as ApplicationContract; |
9 | 9 | use Illuminate\Events\Dispatcher as EventsDispatcher; |
10 | 10 | use Illuminate\Foundation\Application as FoundationApplication; |
| 11 | +use Illuminate\Foundation\Console\Kernel; |
11 | 12 | use Illuminate\Tests\Console\Fixtures\FakeCommandWithArrayInputPrompting; |
12 | 13 | use Illuminate\Tests\Console\Fixtures\FakeCommandWithInputPrompting; |
13 | 14 | use Mockery as m; |
@@ -241,6 +242,35 @@ public function testCallMethodCanCallArtisanCommandUsingCommandClassObject() |
241 | 242 | $this->assertSame(0, $exitCode); |
242 | 243 | } |
243 | 244 |
|
| 245 | + public function testLoadIgnoresTestFiles() |
| 246 | + { |
| 247 | + $dir = __DIR__.'/laravel'; |
| 248 | + @mkdir($dir.'/app/Console/Commands', 0755, true); |
| 249 | + file_put_contents($dir.'/composer.json', json_encode(['autoload' => ['psr-4' => ['App\\' => 'app/']]])); |
| 250 | + file_put_contents($dir.'/app/Console/Commands/ExampleCommand.php', '<?php namespace App\Console\Commands; class ExampleCommand extends \Illuminate\Console\Command { protected $signature = "example"; public function handle() {} }'); |
| 251 | + file_put_contents($dir.'/app/Console/Commands/ExampleCommandTest.php', '<?php namespace App\Console\Commands; class ExampleCommandTest extends \Illuminate\Console\Command { protected $signature = "example-test"; public function handle() {} }'); |
| 252 | + |
| 253 | + try { |
| 254 | + $app = new FoundationApplication($dir); |
| 255 | + $events = new EventsDispatcher($app); |
| 256 | + $app->instance('events', $events); |
| 257 | + |
| 258 | + $kernel = new TestKernel($app, $events); |
| 259 | + $kernel->loadFrom([$dir.'/app/Console/Commands']); |
| 260 | + |
| 261 | + $this->assertContains('App\Console\Commands\ExampleCommand', $kernel->loadedCommands); |
| 262 | + $this->assertNotContains('App\Console\Commands\ExampleCommandTest', $kernel->loadedCommands); |
| 263 | + } finally { |
| 264 | + @unlink($dir.'/app/Console/Commands/ExampleCommand.php'); |
| 265 | + @unlink($dir.'/app/Console/Commands/ExampleCommandTest.php'); |
| 266 | + @unlink($dir.'/composer.json'); |
| 267 | + @rmdir($dir.'/app/Console/Commands'); |
| 268 | + @rmdir($dir.'/app/Console'); |
| 269 | + @rmdir($dir.'/app'); |
| 270 | + @rmdir($dir); |
| 271 | + } |
| 272 | + } |
| 273 | + |
244 | 274 | protected function getMockConsole(array $methods) |
245 | 275 | { |
246 | 276 | $app = m::mock(ApplicationContract::class, ['version' => '6.0']); |
@@ -273,3 +303,18 @@ class CommandWithAliasViaProperty extends Command |
273 | 303 | public $name = 'command-name'; |
274 | 304 | public $aliases = ['command-alias']; |
275 | 305 | } |
| 306 | + |
| 307 | +class TestKernel extends Kernel |
| 308 | +{ |
| 309 | + public $loadedCommands = []; |
| 310 | + |
| 311 | + public function loadFrom($paths) |
| 312 | + { |
| 313 | + $this->load($paths); |
| 314 | + } |
| 315 | + |
| 316 | + protected function commandClassFromFile(\SplFileInfo $file, string $namespace): string |
| 317 | + { |
| 318 | + return tap(parent::commandClassFromFile($file, $namespace), fn ($command) => $this->loadedCommands[] = $command); |
| 319 | + } |
| 320 | +} |
0 commit comments