1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Micro framework package. |
7
|
|
|
* |
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Micro\Plugin\Console\Test\Unit\Business\Factory; |
15
|
|
|
|
16
|
|
|
use Micro\Component\DependencyInjection\Autowire\AutowireHelperInterface; |
17
|
|
|
use Micro\Plugin\Console\Business\Factory\ConsoleApplicationFactory; |
18
|
|
|
use Micro\Plugin\Locator\Facade\LocatorFacadeInterface; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
use Symfony\Component\Console\Application; |
21
|
|
|
use Symfony\Component\Console\Command\Command; |
22
|
|
|
|
23
|
|
|
class ConsoleApplicationFactoryTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
public function testCreate() |
26
|
|
|
{ |
27
|
|
|
$commands = new \ArrayObject([ConsoleApplicationCommandTest::class]); |
28
|
|
|
$locator = $this->createMock(LocatorFacadeInterface::class); |
29
|
|
|
$locator |
30
|
|
|
->expects($this->once()) |
31
|
|
|
->method('lookup') |
32
|
|
|
->willReturn($commands); |
33
|
|
|
|
34
|
|
|
$autowire = $this->createMock(AutowireHelperInterface::class); |
35
|
|
|
$autowire |
36
|
|
|
->expects($this->once()) |
37
|
|
|
->method('autowire') |
38
|
|
|
->with(ConsoleApplicationCommandTest::class) |
39
|
|
|
->willReturn(fn () => new ConsoleApplicationCommandTest()); |
40
|
|
|
|
41
|
|
|
$factory = new ConsoleApplicationFactory( |
42
|
|
|
$locator, |
43
|
|
|
$autowire, |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$app = $factory->create(); |
47
|
|
|
$this->assertInstanceOf(Application::class, $app); |
48
|
|
|
$this->assertInstanceOf(ConsoleApplicationCommandTest::class, $app->get('cmd:test')); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
class ConsoleApplicationCommandTest extends Command |
53
|
|
|
{ |
54
|
|
|
public function __construct() |
55
|
|
|
{ |
56
|
|
|
parent::__construct('cmd:test'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|