1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PHPChunkit; |
6
|
|
|
|
7
|
|
|
use PHPChunkit\Command; |
8
|
|
|
use Symfony\Component\Console\Application; |
9
|
|
|
use Symfony\Component\Console\Command\Command as SymfonyCommand; |
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
12
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
13
|
|
|
use Symfony\Component\Console\Input\InputOption; |
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @testClass PHPChunkit\Test\PHPChunkitApplicationTest |
18
|
|
|
*/ |
19
|
|
|
class PHPChunkitApplication |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Container |
23
|
|
|
*/ |
24
|
|
|
private $container; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var Application |
28
|
|
|
*/ |
29
|
|
|
private $symfonyApplication; |
30
|
|
|
|
31
|
1 |
|
public function __construct(Container $container) |
32
|
|
|
{ |
33
|
1 |
|
$this->container = $container; |
34
|
1 |
|
$this->symfonyApplication = $this->container['phpchunkit.symfony_application']; |
35
|
1 |
|
} |
36
|
|
|
|
37
|
1 |
|
public function run(InputInterface $input, OutputInterface $output) : int |
38
|
|
|
{ |
39
|
1 |
|
$this->container['phpchunkit.application.input'] = $input; |
40
|
1 |
|
$this->container['phpchunkit.application.output'] = $output; |
41
|
|
|
|
42
|
|
|
$commands = [ |
43
|
1 |
|
'sandbox' => 'phpchunkit.command.build_sandbox', |
44
|
|
|
'create-dbs' => 'phpchunkit.command.create_databases', |
45
|
|
|
'watch' => 'phpchunkit.command.test_watcher', |
46
|
|
|
'run' => 'phpchunkit.command.run', |
47
|
|
|
'generate' => 'phpchunkit.command.generate_test', |
48
|
|
|
]; |
49
|
|
|
|
50
|
1 |
|
foreach ($commands as $name => $service) { |
51
|
1 |
|
$service = $this->container[$service]; |
52
|
|
|
|
53
|
1 |
|
$symfonyCommand = $this->register($name); |
54
|
|
|
|
55
|
1 |
|
$service->configure($symfonyCommand); |
56
|
|
|
|
57
|
1 |
|
$symfonyCommand->setCode([$service, 'execute']); |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
return $this->runSymfonyApplication($input, $output); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function runSymfonyApplication( |
64
|
|
|
InputInterface $input, |
65
|
|
|
OutputInterface $output) : int |
66
|
|
|
{ |
67
|
|
|
return $this->symfonyApplication->run($input, $output); |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
private function register(string $name) : SymfonyCommand |
71
|
|
|
{ |
72
|
1 |
|
return $this->symfonyApplication->register($name); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|