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

testCreateFromLogWithAbnormalTermination()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
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\TestResult;
6
7
use Paraunit\Parser\JSON\LogFetcher;
8
use Paraunit\TestResult\FullTestResult;
9
use Paraunit\TestResult\MuteTestResult;
10
use Paraunit\TestResult\TestResultFactory;
11
use Paraunit\TestResult\TestResultFormat;
12
use Paraunit\TestResult\TestResultWithAbnormalTermination;
13
use Paraunit\TestResult\TestResultWithMessage;
14
use Tests\BaseUnitTestCase;
15
16
/**
17
 * Class TestResultFactoryTest
18
 * @package Tests\Unit\TestResult
19
 */
20
class TestResultFactoryTest extends BaseUnitTestCase
21
{
22 View Code Duplication
    public function testCreateFromLogMuteWithoutTestName()
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...
23
    {
24
        $log = new \stdClass();
25
        $log->event = 'test';
26
27
        $factory = new TestResultFactory();
28
        $result = $factory->createFromLog($log);
29
30
        $this->assertInstanceOf(MuteTestResult::class, $result);
31
        $this->assertInstanceOf(TestResultFormat::class, $result->getTestResultFormat());
32
    }
33
34 View Code Duplication
    public function testCreateFromLogMute()
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...
35
    {
36
        $log = new \stdClass();
37
        $log->test = 'testFunction()';
38
        $log->event = 'test';
39
40
        $factory = new TestResultFactory();
41
        $result = $factory->createFromLog($log);
42
43
        $this->assertInstanceOf(MuteTestResult::class, $result);
44
        $this->assertInstanceOf(TestResultFormat::class, $result->getTestResultFormat());
45
    }
46
47
    public function testCreateFromLogWithMessage()
48
    {
49
        $log = $this->getLogFromStub('test', 'error');
50
        unset($log->trace);
51
52
        $factory = new TestResultFactory();
53
        /** @var TestResultWithMessage $result */
54
        $result = $factory->createFromLog($log);
55
56
        $this->assertInstanceOf(TestResultWithMessage::class, $result);
57
        $this->assertInstanceOf(TestResultFormat::class, $result->getTestResultFormat());
58
        $this->assertEquals($log->test, $result->getFunctionName());
59
    }
60
61
    public function testCreateFromLogWithTrace()
62
    {
63
        $log = $this->getLogWithTrace();
64
65
        $factory = new TestResultFactory();
66
        /** @var FullTestResult $result */
67
        $result = $factory->createFromLog($log);
68
69
        $this->assertInstanceOf(FullTestResult::class, $result);
70
        $this->assertInstanceOf(TestResultFormat::class, $result->getTestResultFormat());
71
        $this->assertEquals($log->message, $result->getFailureMessage());
72
        $this->assertSame($log->trace, $result->getTrace());
73
    }
74
75
    public function testCreateFromLogWithAbnormalTermination()
76
    {
77
        $log = $this->getLogFromStub();
78
        $log->status = LogFetcher::LOG_ENDING_STATUS;
79
        $log->test = 'testFunction()';
80
81
        $factory = new TestResultFactory();
82
        /** @var TestResultWithAbnormalTermination $result */
83
        $result = $factory->createFromLog($log);
84
85
        $this->assertInstanceOf(TestResultWithAbnormalTermination::class, $result);
86
        $this->assertInstanceOf(TestResultFormat::class, $result->getTestResultFormat());
87
        // TestStartParser injects the last launched test function name
88
        $this->assertEquals($log->test, $result->getFunctionName());
89
        $this->assertStringStartsWith('Abnormal termination -- complete test output:', $result->getFailureMessage());
90
    }
91
}
92