Completed
Pull Request — stable (#91)
by Mior Muhammad Zaki
11:58
created

TestCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 4
dl 0
loc 53
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 8 1
A execute() 0 10 2
1
<?php
2
3
/**
4
 * This file is part of Collision.
5
 *
6
 * (c) Nuno Maduro <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 */
11
12
namespace NunoMaduro\Collision\Adapters\Phpunit\Commands;
13
14
use NunoMaduro\Collision\Adapters\Phpunit\TestRunner;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
use Symfony\Component\Console\Style\SymfonyStyle;
20
21
class TestCommand extends Command
22
{
23
    /**
24
     * Test working path.
25
     *
26
     * @var string
27
     */
28
    protected $workingPath;
29
30
    /**
31
     * Create a new command instance.
32
     *
33
     * @param  string  $workingPath
34
     */
35
    public function __construct(string $workingPath)
36
    {
37
        $this->workingPath = $workingPath;
38
39
        parent::__construct();
40
    }
41
42
    /**
43
     * Configure the command options.
44
     *
45
     * @return void
46
     */
47
    protected function configure()
48
    {
49
        $this->ignoreValidationErrors();
50
51
        $this->setName('run')
52
            ->setDescription('Run the tests.')
53
            ->addOption('without-tty', null, InputOption::VALUE_NONE, 'Disable output to TTY.');
54
    }
55
56
    /**
57
     * Execute the command.
58
     *
59
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
60
     *
61
     * @return int 0 if everything went fine, or an exit code
62
     */
63
    protected function execute(InputInterface $input, OutputInterface $output)
64
    {
65
        $withoutTty = $input->getOption('without-tty');
66
67
        $options = array_slice($_SERVER['argv'], $withoutTty ? 3 : 2);
68
69
        $runner = new TestRunner($this->workingPath, (bool) $withoutTty);
70
71
        return $runner(new SymfonyStyle($input, $output), $options);
72
    }
73
}
74