RunTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 64.29%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 96
ccs 27
cts 42
cp 0.6429
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A handleBrowser() 0 6 1
A handleDomain() 0 6 1
A runTestFromFile() 0 12 1
B runCommand() 0 24 3
A getCommand() 0 4 1
A setCommand() 0 4 1
A getPathToCommand() 0 4 1
A setPathToCommand() 0 4 1
1
<?php
2
3
4
namespace GD;
5
6
use Silly\Edition\Pimple\Application;
7
use Symfony\Component\Process\Process;
8
9
class RunTest extends BaseGherkinToDusk
10
{
11
12
13
    /**
14
     * @var string
15
     */
16
    protected $command;
17
18
    protected $path_to_command;
19
20 3
    public function handleBrowser($path)
21
    {
22 3
        $this->context = 'browser';
23 3
        $this->setPathToCommand('php artisan dusk');
24 3
        $this->runTestFromFile($path);
25 3
    }
26
27 3
    public function handleDomain($path)
28
    {
29 3
        $this->context = 'domain';
30 3
        $this->setPathToCommand('vendor/bin/phpunit');
31 3
        $this->runTestFromFile($path);
32 3
    }
33
34
35 6
    private function runTestFromFile($path)
36
    {
37 6
        $this->setPathToFeature($path)->buildDuskTestName();
38
39 6
        $path_to_test = $this->fullPathToDestinationFile();
40
41 6
        $path_to_command = $this->getPathToCommand();
42
43 6
        $this->setCommand(sprintf("%s %s", $path_to_command, $path_to_test));
44
45 6
        $this->runCommand();
46 6
    }
47
48
    protected function runCommand()
49
    {
50
        $process = new \Symfony\Component\Process\Process($this->command);
51
52
        $process->setTimeout(600);
53
54
        $process->start();
55
56
        $process->wait(function ($type, $buffer) use ($process) {
57
            if (Process::ERR === $type) {
58
                $this->app->getContainer()['output']->write($buffer);
59
            } else {
60
                $this->app->getContainer()['output']->write($buffer);
61
            }
62
        });
63
64
        if (!$process->isSuccessful()) {
65
            //throw new ProcessFailedException($process);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
            $this->app->getContainer()['output']->writeln("<error>Error with tests....</error>");
67
            exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method runCommand() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
68
        } else {
69
            $this->app->getContainer()['output']->writeln("<fg=black;bg=green>All Tests Passed...</>");
70
        }
71
    }
72
73
    /**
74
     * @return string
75
     */
76 6
    public function getCommand()
77
    {
78 6
        return $this->command;
79
    }
80
81
    /**
82
     * @param string $command
83
     */
84 6
    public function setCommand($command)
85
    {
86 6
        $this->command = $command;
87 6
    }
88
89
    /**
90
     * @return mixed
91
     */
92 6
    public function getPathToCommand()
93
    {
94 6
        return $this->path_to_command;
95
    }
96
97
    /**
98
     * @param mixed $path_to_command
99
     */
100 6
    public function setPathToCommand($path_to_command)
101
    {
102 6
        $this->path_to_command = $path_to_command;
103 6
    }
104
}
105