Completed
Push — master ( d308b8...b73d2a )
by Alessandro
08:43
created

TestResultFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Paraunit\TestResult;
4
5
use Paraunit\Parser\JSONLogFetcher;
6
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface;
7
8
/**
9
 * Class TestResultFactory
10
 * @package Paraunit\TestResult
11
 */
12
class TestResultFactory
13
{
14
    /**
15
     * @param \stdClass $log
16
     * @return PrintableTestResultInterface
17
     */
18
    public function createFromLog(\stdClass $log)
19
    {
20
        if (property_exists($log, 'status') && $log->status === JSONLogFetcher::LOG_ENDING_STATUS) {
21 45
            return new TestResultWithAbnormalTermination(
22
                $log->test,
23 45
                'Abnormal termination -- complete test output:'
24 45
            );
25
        }
26
27
        if (! property_exists($log, 'message')) {
28
            return new MuteTestResult();
29
        }
30 29
31
        if (property_exists($log, 'trace')) {
32 29
            $result = new FullTestResult($log->test, $log->message);
33 11
            $this->addTraceToResult($result, $log);
34 11
35 11
            return $result;
36
        }
37 11
38
        return new TestResultWithMessage($log->test, $log->message);
39
    }
40 23
41 5
    /**
42
     * @param FullTestResult $result
43
     * @param \stdClass $log
44 20
     */
45 19
    private function addTraceToResult(FullTestResult $result, \stdClass $log)
46 19
    {
47
        foreach ($log->trace as $traceStep) {
48 19
            $result->addTraceStep(new TraceStep($traceStep->file, $traceStep->line));
49
        }
50
    }
51
}
52