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

ProcessFactoryTest::testCreateProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 42

Duplication

Lines 42
Ratio 100 %

Importance

Changes 0
Metric Value
dl 42
loc 42
rs 9.248
c 0
b 0
f 0
cc 1
nc 1
nop 0
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