1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Bluz PHP Team |
4
|
|
|
* @link https://github.com/bluzphp/bluzman |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Bluzman\Command; |
8
|
|
|
|
9
|
|
|
use Codeception; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Input\StringInput; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class List command |
17
|
|
|
* |
18
|
|
|
* @package Bluzman\Command |
19
|
|
|
* |
20
|
|
|
* @author Pavel Machekhin |
21
|
|
|
* @created 2013-03-28 14:03 |
22
|
|
|
*/ |
23
|
|
|
class TestCommand extends AbstractCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Command configuration |
27
|
|
|
*/ |
28
|
14 |
|
protected function configure() |
29
|
|
|
{ |
30
|
|
|
$this |
31
|
|
|
// the name of the command (the part after "bin/bluzman") |
32
|
14 |
|
->setName('test') |
33
|
|
|
// the short description shown while running "php bin/bluzman list" |
34
|
14 |
|
->setDescription('Run tests') |
35
|
|
|
// the full command description shown when running the command with |
36
|
|
|
// the "--help" option |
37
|
14 |
|
->setHelp('Run codeception tests') |
38
|
|
|
; |
39
|
|
|
|
40
|
14 |
|
$module = new InputArgument( |
41
|
14 |
|
'module', |
42
|
14 |
|
InputArgument::OPTIONAL, |
43
|
14 |
|
'Run tests of module group' |
44
|
|
|
); |
45
|
|
|
|
46
|
14 |
|
$this->getDefinition()->addArgument($module); |
47
|
14 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param InputInterface $input |
51
|
|
|
* @param OutputInterface $output |
52
|
|
|
* @return int|null|void |
53
|
|
|
*/ |
54
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
55
|
|
|
{ |
56
|
|
|
// call `codeception run` command programmatically |
57
|
|
|
$arguments = [ |
58
|
|
|
'run', |
59
|
|
|
'--config '. PATH_ROOT .DS. 'codeception.yml' |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
if ($group = $input->getArgument('module')) { |
63
|
|
|
$arguments[] = '--group ' . $group; |
64
|
|
|
} |
65
|
|
|
$codeceptionInput = new StringInput(implode(' ', $arguments)); |
66
|
|
|
$command = $this->getCodeceptionApplication()->find('run'); |
67
|
|
|
|
68
|
|
|
$command->run($codeceptionInput, $output); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Return CodeceptionApplication |
73
|
|
|
*/ |
74
|
|
|
protected function getCodeceptionApplication() |
75
|
|
|
{ |
76
|
|
|
// @todo need refactoring this part - move functions to separate files |
77
|
|
|
require_once PATH_VENDOR .DS. 'codeception' .DS. 'codeception' .DS. 'autoload.php'; |
78
|
|
|
|
79
|
|
|
$app = new Codeception\Application('Codeception', Codeception\Codecept::VERSION); |
80
|
|
|
$app->add(new Codeception\Command\Run('run')); |
81
|
|
|
|
82
|
|
|
$app->registerCustomCommands(); |
83
|
|
|
|
84
|
|
|
return $app; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|