Passed
Pull Request — master (#59)
by Raúl
04:00
created

LogEntryTest::testJsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Tests\Pagantis\ModuleUtils\Model\Log;
4
5
use PHPUnit\Framework\TestCase;
6
use Pagantis\ModuleUtils\Model\Log\LogEntry;
7
8
class LogEntryTest extends TestCase
9
{
10
    /**
11
     * INFO_MESSAGE
12
     */
13
    const INFO_MESSAGE = 'Success message';
14
15
    /**
16
     * ERROR_MESSAGE
17
     */
18
    const ERROR_MESSAGE = 'Error message';
19
20
    /**
21
     * testInfo
22
     */
23
    public function testInfo()
24
    {
25
        $logEntry = new LogEntry();
26
        $logEntry->info(self::INFO_MESSAGE);
27
28
        $this->assertEquals(self::INFO_MESSAGE, $logEntry->getMessage());
29
        $this->assertInstanceOf('Pagantis\ModuleUtils\Model\Log\LogEntry', $logEntry);
30
    }
31
32
    /**
33
     * testError
34
     *
35
     * @throws \ReflectionException
36
     */
37
    public function testError()
38
    {
39
        $logEntry = new LogEntry();
40
        $logEntry->error(new \Exception(self::INFO_MESSAGE));
41
        
42
        $reflectCreateOrderMethod = new \ReflectionClass('Pagantis\ModuleUtils\Model\Log\LogEntry');
43
        $property = $reflectCreateOrderMethod->getProperty('message');
44
        $property->setAccessible(true);
45
        $this->assertEquals($property->getValue($logEntry), $logEntry->getMessage());
46
        
47
        $property = $reflectCreateOrderMethod->getProperty('code');
48
        $property->setAccessible(true);
49
        $this->assertEquals($property->getValue($logEntry), $logEntry->getCode());
50
        
51
        $property = $reflectCreateOrderMethod->getProperty('line');
52
        $property->setAccessible(true);
53
        $this->assertEquals($property->getValue($logEntry), $logEntry->getLine());
54
        
55
        $property = $reflectCreateOrderMethod->getProperty('file');
56
        $property->setAccessible(true);
57
        $this->assertEquals($property->getValue($logEntry), $logEntry->getFile());
58
        
59
        $property = $reflectCreateOrderMethod->getProperty('trace');
60
        $property->setAccessible(true);
61
        $this->assertEquals($property->getValue($logEntry), $logEntry->getTrace());
62
63
        $this->assertInstanceOf('Pagantis\ModuleUtils\Model\Log\LogEntry', $logEntry);
64
    }
65
66
    /**
67
     * testToJson
68
     */
69
    public function testToJson()
70
    {
71
        $logEntry = new LogEntry();
72
        $logEntry->info(self::INFO_MESSAGE);
73
        $jsonArray = $logEntry->toJson();
74
75
        $this->assertJson($jsonArray);
76
    }
77
78
    /**
79
     * testJsonSerialize
80
     */
81
    public function testJsonSerialize()
82
    {
83
        $logEntry = new LogEntry();
84
        $logEntry->info(self::INFO_MESSAGE);
85
        $jsonArray = $logEntry->jsonSerialize();
86
87
        $this->assertArrayHasKey('message', $jsonArray);
88
        $this->assertEquals($logEntry->getMessage(), self::INFO_MESSAGE);
89
    }
90
}
91