Completed
Pull Request — master (#218)
by
unknown
03:00
created

ParaTestCommand::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2.0065

Importance

Changes 6
Bugs 2 Features 3
Metric Value
c 6
b 2
f 3
dl 0
loc 20
ccs 15
cts 17
cp 0.8824
rs 9.4285
cc 2
eloc 15
nc 2
nop 0
crap 2.0065
1
<?php namespace ParaTest\Console\Commands;
2
3
use Composer\Semver\Comparator;
4
use Symfony\Component\Console\Command\Command;
5
use Symfony\Component\Console\Input\InputOption;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use ParaTest\Console\Testers\Tester;
9
10
class ParaTestCommand extends Command
11
{
12
    /**
13
     * @var \ParaTest\Console\Testers\Tester
14
     */
15
    protected $tester;
16
17 7
    public function __construct(Tester $tester)
18
    {
19 7
        parent::__construct('paratest');
20 7
        $this->tester = $tester;
21 7
        $this->tester->configure($this);
22 7
    }
23
24
    /**
25
     * @return bool
26
     */
27 9
    public static function isWhitelistSupported()
28
    {
29 9
        return Comparator::greaterThanOrEqualTo(\PHPUnit_Runner_Version::id(), '5.0.0');
30
    }
31
32
    /**
33
     * Ubiquitous configuration options for ParaTest
34
     */
35 7
    protected function configure()
36
    {
37 7
        $this
38 7
            ->addOption('processes', 'p', InputOption::VALUE_REQUIRED, 'The number of test processes to run.', 5)
39 7
            ->addOption('functional', 'f', InputOption::VALUE_NONE, 'Run methods instead of suites in separate processes.')
40 7
            ->addOption('no-test-tokens', null, InputOption::VALUE_NONE, 'Disable TEST_TOKEN environment variables. <comment>(default: variable is set)</comment>')
41 7
            ->addOption('help', 'h', InputOption::VALUE_NONE, 'Display this help message.')
42 7
            ->addOption('coverage-clover', null, InputOption::VALUE_REQUIRED, 'Generate code coverage report in Clover XML format.')
43 7
            ->addOption('coverage-html', null, InputOption::VALUE_REQUIRED, 'Generate code coverage report in HTML format.')
44 7
            ->addOption('coverage-php', null, InputOption::VALUE_REQUIRED, 'Serialize PHP_CodeCoverage object to file.')
45 7
            ->addOption('max-batch-size', 'm', InputOption::VALUE_REQUIRED, 'Max batch size (only for functional mode).', 0)
46 7
            ->addOption('filter', null, InputOption::VALUE_REQUIRED, 'Filter (only for functional mode).')
47 7
            ->addOption('repeat', null, InputOption::VALUE_REQUIRED, 'Runs the test(s) repeatedly.', 1)
48 7
            ->addOption('only-repeat-failed', null, InputOption::VALUE_NONE, 'Repeat only failing tests.', null);
49
50
51 7
        if (self::isWhitelistSupported()) {
52
            $this->addOption('whitelist', null, InputOption::VALUE_REQUIRED, 'Directory to add to the coverage whitelist.');
53
        }
54 7
    }
55
56
    /**
57
     * Executes the specified tester
58
     *
59
     * @param InputInterface $input
60
     * @param OutputInterface $output
61
     * @return int|mixed|null
62
     */
63 1
    public function execute(InputInterface $input, OutputInterface $output)
64
    {
65 1
        return $this->tester->execute($input, $output);
66
    }
67
}
68