|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral Framework, SpiralScout LLC. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Vladislav Gorenkin (vladgorenkin) |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace Spiral\Tests\Console; |
|
12
|
|
|
|
|
13
|
|
|
use Spiral\Console\CommandLocator; |
|
14
|
|
|
use Spiral\Console\StaticLocator; |
|
15
|
|
|
use Spiral\Tests\Console\Fixtures\LazyLoadedCommand; |
|
16
|
|
|
use Spiral\Tokenizer\ClassesInterface; |
|
17
|
|
|
use Symfony\Component\Console\Command\LazyCommand; |
|
18
|
|
|
|
|
19
|
|
|
class LazyTest extends BaseTest |
|
20
|
|
|
{ |
|
21
|
|
|
public function testLazyCommandCreationInCommandLocator(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$locator = new CommandLocator( |
|
24
|
|
|
new class() implements ClassesInterface { |
|
25
|
|
|
public function getClasses($target = null): array |
|
26
|
|
|
{ |
|
27
|
|
|
return [ |
|
28
|
|
|
new \ReflectionClass(LazyLoadedCommand::class), |
|
29
|
|
|
]; |
|
30
|
|
|
} |
|
31
|
|
|
}, |
|
32
|
|
|
$this->container |
|
33
|
|
|
); |
|
34
|
|
|
$commands = $locator->locateCommands(); |
|
35
|
|
|
$command = reset($commands); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertInstanceOf(LazyCommand::class, $command); |
|
38
|
|
|
$this->assertSame('lazy', $command->getName()); |
|
39
|
|
|
$this->assertSame('Lazy description', $command->getDescription()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testLazyCommandCreationInStaticLocator(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$locator = new StaticLocator([LazyLoadedCommand::class]); |
|
45
|
|
|
$commands = $locator->locateCommands(); |
|
46
|
|
|
$command = reset($commands); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertInstanceOf(LazyCommand::class, $command); |
|
49
|
|
|
$this->assertSame('lazy', $command->getName()); |
|
50
|
|
|
$this->assertSame('Lazy description', $command->getDescription()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testLazyCommandExecution(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$core = $this->getCore(new StaticLocator([LazyLoadedCommand::class])); |
|
56
|
|
|
$output = $core->run('lazy'); |
|
57
|
|
|
$this->assertSame('OK', $output->getOutput()->fetch()); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|