Completed
Push — output_parsers_refactor ( 755930...b5c5df )
by Alessandro
07:17
created

testPrintProcessResultWithAbnormalTermination()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Paraunit\Tests\Unit;
4
5
use Paraunit\Lifecycle\ProcessEvent;
6
use Paraunit\Printer\ProcessPrinter;
7
use Paraunit\Tests\Stub\ConsoleOutputStub;
8
use Paraunit\Tests\Stub\StubbedParaProcess;
9
use Prophecy\Argument;
10
11
class ProcessPrinterTest extends \PHPUnit_Framework_TestCase
12
{
13 View Code Duplication
    public function testPrintProcessResultWithRetry()
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...
14
    {
15
        $process = new StubbedParaProcess();
16
        $process->setIsToBeRetried(true);
17
18
        $printer = new ProcessPrinter();
19
        $output = new ConsoleOutputStub();
20
21
        $processEvent = new ProcessEvent($process, array('output_interface' => $output));
22
        $printer->onProcessTerminated($processEvent);
23
24
        $this->assertEquals('<ok>A</ok>', $output->getOutput());
25
    }
26
27
    public function testPrintProcessResultWithAbnormalTermination()
28
    {
29
        $process = new StubbedParaProcess();
30
        $process->reportAbnormalTerminationInFunction('die()');
31
32
        $printer = new ProcessPrinter();
33
        $output = new ConsoleOutputStub();
34
35
        $processEvent = new ProcessEvent($process, array('output_interface' => $output));
36
        $printer->onProcessTerminated($processEvent);
37
38
        $this->assertEquals('<halted>X</halted>', $output->getOutput());
39
    }
40
41
    /**
42
     * @dataProvider newLineTimesProvider
43
     */
44
    public function testPrintProcessResult_new_line_after_80_chars($times, $newLineTimes)
45
    {
46
        $process = new StubbedParaProcess();
47
        $process->setTestResults(array_fill(0, $times, 'F'));
48
49
        $printer = new ProcessPrinter();
50
        $output = $this->prophesize('Paraunit\Tests\Stub\ConsoleOutputStub');
51
        $output->write('<fail>F</fail>')->willReturn()->shouldBeCalledTimes($times);
52
        $output->writeln('')->willReturn()->shouldBeCalledTimes($newLineTimes);
53
54
        $processEvent = new ProcessEvent($process, array('output_interface' => $output->reveal()));
55
        $printer->onProcessTerminated($processEvent);
56
    }
57
58
    public function newLineTimesProvider()
59
    {
60
        return array(
61
            array(79, 0),
62
            array(80, 0),
63
            array(81, 1),
64
            array(200, 2),
65
            array(240, 2),
66
            array(241, 3),
67
        );
68
    }
69
70
    /**
71
     * @dataProvider testResultProvider
72
     */
73 View Code Duplication
    public function testPrintProcessResult_proper_output_with_normal_testresults($testResult, $expectedOutput)
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...
74
    {
75
        $process = new StubbedParaProcess();
76
        $process->setTestResults(array($testResult));
77
78
        $printer = new ProcessPrinter();
79
        $output = new ConsoleOutputStub();
80
81
        $processEvent = new ProcessEvent($process, array('output_interface' => $output));
82
        $printer->onProcessTerminated($processEvent);
83
84
        $this->assertEquals($expectedOutput, $output->getOutput());
85
    }
86
87
    public function testResultProvider()
88
    {
89
        return array(
90
            array('F', '<fail>F</fail>'),
91
            array('E', '<error>E</error>'),
92
            array('I', '<incomplete>I</incomplete>'),
93
            array('S', '<skipped>S</skipped>'),
94
            array('R', '<risky>R</risky>'),
95
            array('W', '<warning>W</warning>'),
96
            array(null, '<warning>?</warning>'),
97
        );
98
    }
99
}
100