|
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
|
|
|
/** @var TestResultFormat */ |
|
15
|
|
|
private $format; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* TestResultFactory constructor. |
|
19
|
|
|
* @param TestResultFormat $format |
|
20
|
|
|
*/ |
|
21
|
41 |
|
public function __construct(TestResultFormat $format) |
|
22
|
|
|
{ |
|
23
|
41 |
|
$this->format = $format; |
|
24
|
41 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param \stdClass $log |
|
28
|
|
|
* @return PrintableTestResultInterface |
|
29
|
|
|
*/ |
|
30
|
26 |
|
public function createFromLog(\stdClass $log) |
|
31
|
|
|
{ |
|
32
|
26 |
|
if (property_exists($log, 'status') && $log->status == JSONLogFetcher::LOG_ENDING_STATUS) { |
|
33
|
8 |
|
return new TestResultWithAbnormalTermination( |
|
34
|
8 |
|
$this->format, |
|
35
|
8 |
|
$log->test, |
|
36
|
|
|
'Abnormal termination -- complete test output:' |
|
37
|
8 |
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
22 |
|
if ( ! property_exists($log, 'message')) { |
|
41
|
4 |
|
return new MuteTestResult(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
19 |
|
if (property_exists($log, 'trace')) { |
|
45
|
18 |
|
$result = new FullTestResult($this->format, $log->test, $log->message); |
|
46
|
18 |
|
$this->addTraceToResult($result, $log); |
|
47
|
|
|
|
|
48
|
18 |
|
return $result; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
return new TestResultWithMessage($this->format, $log->test, $log->message); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param FullTestResult $result |
|
56
|
|
|
* @param \stdClass $log |
|
57
|
|
|
*/ |
|
58
|
18 |
|
private function addTraceToResult(FullTestResult $result, $log) |
|
59
|
|
|
{ |
|
60
|
18 |
|
foreach ($log->trace as $traceStep) { |
|
61
|
10 |
|
$result->addTraceStep(new TraceStep($traceStep->file, $traceStep->line)); |
|
62
|
18 |
|
} |
|
63
|
18 |
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|