Completed
Pull Request — master (#30)
by Anton
17:34
created

TestCommand::getCodeceptionApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 12
ccs 0
cts 6
cp 0
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 6
nc 1
nop 0
crap 2
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
        $this->addModuleArgument(InputArgument::OPTIONAL);
41 14
    }
42
43
    /**
44
     * @param InputInterface $input
45
     * @param OutputInterface $output
46
     * @return int|null|void
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        // call `codeception run` command programmatically
51
        $arguments = [
52
            'run',
53
            '--config '. PATH_ROOT .DS. 'codeception.yml'
54
        ];
55
56
        if ($group = $input->getArgument('module')) {
57
            $arguments[] = '--group ' . $group;
58
        }
59
        $codeceptionInput = new StringInput(implode(' ', $arguments));
60
        $command = $this->getCodeceptionApplication()->find('run');
61
62
        $command->run($codeceptionInput, $output);
63
    }
64
65
    /**
66
     * Return CodeceptionApplication
67
     */
68
    protected function getCodeceptionApplication()
69
    {
70
        // @todo need refactoring this part - move functions to separate files
71
        require_once PATH_VENDOR .DS. 'codeception' .DS. 'codeception' .DS. 'autoload.php';
72
73
        $app = new Codeception\Application('Codeception', Codeception\Codecept::VERSION);
74
        $app->add(new Codeception\Command\Run('run'));
75
76
        $app->registerCustomCommands();
77
78
        return $app;
79
    }
80
}
81