Completed
Branch output_parsers_refactor (d2cb12)
by Alessandro
02:20
created

ProcessFactoryTest::testCreateProcess()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
namespace Paraunit\Tests\Unit\Process;
4
5
use Paraunit\Process\ProcessFactory;
6
7
/**
8
 * Class ProcessFactoryTest
9
 * @package Paraunit\Tests\Unit\Process
10
 */
11
class ProcessFactoryTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testCreateProcess()
14
    {
15
        $phpUnitBin = $this->prophesize('Paraunit\Configuration\PHPUnitBinFile');
16
        $phpUnitBin->getPhpUnitBin()->shouldBeCalled()->willReturn('phpunit');
17
18
        $phpUnitConfigFile = $this->prophesize('Paraunit\Configuration\PHPUnitConfigFile');
19
        $phpUnitConfigFile->getFileFullPath()->shouldBeCalled()->willReturn('configFile.xml');
20
21
        $fileName = $this->prophesize('Paraunit\Configuration\JSONLogFilename');
22
        $fileName->generateFromUniqueId(md5('TestTest.php'))->willReturn('log.json');
23
24
        $factory = new ProcessFactory($phpUnitBin->reveal(), $fileName->reveal());
25
        $factory->setConfigFile($phpUnitConfigFile->reveal());
26
27
        $process = $factory->createProcess('TestTest.php');
28
29
        $this->assertInstanceOf('Paraunit\Process\ParaunitProcessAbstract', $process);
30
        $expectedCmdLine = 'phpunit '
31
            . '-c configFile.xml '
32
            . '--colors=never '
33
            . '--log-json=log.json '
34
            . 'TestTest.php '
35
            . '2>&1';
36
        $this->assertEquals($expectedCmdLine, $process->getCommandLine());
37
    }
38
39
    public function testCreateProcessThrowsExceptionIfConfigIsMissing()
40
    {
41
        $phpUnitBin = $this->prophesize('Paraunit\Configuration\PHPUnitBinFile');
42
        $fileName = $this->prophesize('Paraunit\Configuration\JSONLogFileName');
43
44
        $factory = new ProcessFactory($phpUnitBin->reveal(), $fileName->reveal());
45
46
        $this->setExpectedException('\Exception', 'config missing');
47
        $factory->createProcess('test');
48
    }
49
}
50