|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpUnitGen\Executor; |
|
4
|
|
|
|
|
5
|
|
|
use PhpUnitGen\Configuration\ConfigurationInterface\ConsoleConfigInterface; |
|
6
|
|
|
use PhpUnitGen\Exception\ExceptionInterface\ExceptionCatcherInterface; |
|
7
|
|
|
use PhpUnitGen\Exception\ExecutorException; |
|
8
|
|
|
use PhpUnitGen\Executor\ExecutorInterface\ConsoleExecutorInterface; |
|
9
|
|
|
use PhpUnitGen\Executor\ExecutorInterface\DirectoryExecutorInterface; |
|
10
|
|
|
use PhpUnitGen\Executor\ExecutorInterface\FileExecutorInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class ConsoleExecutor. |
|
14
|
|
|
* |
|
15
|
|
|
* @author Paul Thébaud <[email protected]>. |
|
16
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
|
17
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
|
18
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
|
19
|
|
|
* @since Class available since Release 2.0.0. |
|
20
|
|
|
*/ |
|
21
|
|
|
class ConsoleExecutor implements ConsoleExecutorInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var ConsoleConfigInterface $config The configuration to use. |
|
25
|
|
|
*/ |
|
26
|
|
|
private $config; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var DirectoryExecutorInterface $directoryExecutor A directory executor. |
|
30
|
|
|
*/ |
|
31
|
|
|
private $directoryExecutor; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var FileExecutorInterface $fileExecutor A file executor. |
|
35
|
|
|
*/ |
|
36
|
|
|
private $fileExecutor; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var ExceptionCatcherInterface $exceptionCatcher An exception catcher to catch exception. |
|
40
|
|
|
*/ |
|
41
|
|
|
private $exceptionCatcher; |
|
42
|
|
|
|
|
43
|
|
|
public function __construct( |
|
44
|
|
|
ConsoleConfigInterface $config, |
|
45
|
|
|
DirectoryExecutorInterface $directoryExecutor, |
|
46
|
|
|
FileExecutorInterface $fileExecutor, |
|
47
|
|
|
ExceptionCatcherInterface $exceptionCatcher |
|
48
|
|
|
) { |
|
49
|
|
|
$this->config = $config; |
|
50
|
|
|
$this->directoryExecutor = $directoryExecutor; |
|
51
|
|
|
$this->fileExecutor = $fileExecutor; |
|
52
|
|
|
$this->exceptionCatcher = $exceptionCatcher; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function execute(): void |
|
59
|
|
|
{ |
|
60
|
|
|
foreach ($this->config->getDirectories() as $source => $target) { |
|
61
|
|
|
try { |
|
62
|
|
|
$this->directoryExecutor->execute($source, $target); |
|
63
|
|
|
} catch (ExecutorException $exception) { |
|
64
|
|
|
$this->exceptionCatcher->catch($exception); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
foreach ($this->config->getFiles() as $source => $target) { |
|
68
|
|
|
try { |
|
69
|
|
|
$this->fileExecutor->execute($source, $target); |
|
70
|
|
|
} catch (ExecutorException $exception) { |
|
71
|
|
|
$this->exceptionCatcher->catch($exception); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |