Test Failed
Pull Request — master (#132)
by Alessandro
03:15
created

ProcessFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 76.36 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 42
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 2
A testCreateProcess() 42 42 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Process;
6
7
use Paraunit\Configuration\PHPUnitConfig;
8
use Paraunit\Configuration\TempFilenameFactory;
9
use Paraunit\Process\AbstractParaunitProcess;
10
use Paraunit\Process\CommandLine;
11
use Paraunit\Process\ProcessFactory;
12
use Symfony\Component\Process\Process;
13
use Tests\BaseUnitTestCase;
14
15
/**
16
 * Class ProcessFactoryTest
17
 * @package Tests\Unit\Process
18
 */
19
class ProcessFactoryTest extends BaseUnitTestCase
20
{
21
    protected function setUp()
22
    {
23
        $process = new Process(['cmd as array']);
24
        if (\is_array($process->getCommandLine())) {
25
            $this->markTestSkipped('CommandLine not parsed, we have symfony/process < 3.3');
26
        }
27
28
        parent::setUp();
29
    }
30
31 View Code Duplication
    public function testCreateProcess()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $phpUnitConfig = $this->prophesize(PHPUnitConfig::class);
34
        $cliCommand = $this->prophesize(CommandLine::class);
35
        $cliCommand->getExecutable()->willReturn(['sapi', 'executable']);
36
        $cliCommand
37
            ->getOptions($phpUnitConfig->reveal())
38
            ->shouldBeCalled()
39
            ->willReturn(['--configuration=config.xml']);
40
        $cliCommand
41
            ->getSpecificOptions('TestTest.php')
42
            ->shouldBeCalledTimes(1)
43
            ->willReturn(['--specific=value-for-TestTest.php']);
44
        $cliCommand
45
            ->getSpecificOptions('TestTest2.php')
46
            ->shouldBeCalledTimes(1)
47
            ->willReturn(['--specific=value-for-TestTest2.php']);
48
49
        $tempFilenameFactory = $this->prophesize(TempFilenameFactory::class);
50
        $tempFilenameFactory->getPathForLog()
51
            ->willReturn('/path/for/log/');
52
53
        $factory = new ProcessFactory(
54
            $cliCommand->reveal(),
55
            $phpUnitConfig->reveal(),
56
            $tempFilenameFactory->reveal()
57
        );
58
59
        $processWrapper = $factory->create('TestTest.php');
60
61
        $this->assertInstanceOf(AbstractParaunitProcess::class, $processWrapper);
62
        $commandLine = $processWrapper->getCommandLine();
63
        $this->assertContains('TestTest.php', $commandLine);
64
        $this->assertContains('--specific=value-for-TestTest.php', $commandLine);
65
66
        $processWrapper = $factory->create('TestTest2.php');
67
68
        $this->assertInstanceOf(AbstractParaunitProcess::class, $processWrapper);
69
        $commandLine = $processWrapper->getCommandLine();
70
        $this->assertContains('TestTest2.php', $commandLine);
71
        $this->assertContains('--specific=value-for-TestTest2.php', $commandLine);
72
    }
73
}
74