Test Failed
Push — master ( 40a2d1...7a5bc4 )
by Valentin
40s
created

LogServiceTest::testLastLog()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 12

Duplication

Lines 24
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 24
loc 24
rs 8.9713
c 1
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Spiral\Tests\LogViewer;
4
5
use Psr\Log\LogLevel;
6
use Spiral\Debug\Traits\LoggerTrait;
7
use Spiral\LogViewer\Entities\LogFile;
8
use Spiral\LogViewer\Services\LogService;
9
use Spiral\Tests\HttpTest;
10
11
class LogServiceTest extends HttpTest
12
{
13
    use LoggerTrait;
14
15
    /**
16
     * Can get all logs.
17
     */
18 View Code Duplication
    public function testGetLogs()
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...
19
    {
20
        /** @var LogService $service */
21
        $service = $this->container->get(LogService::class);
22
23
        $this->assertEmpty($service->getLogs());
24
25
        $snapshot = $this->makeSnapshot('error', 123);
26
        $snapshot->report();
27
28
        $this->assertCount(1, $service->getLogs());
29
30
        $this->get('/controller/action');
31
        $this->assertCount(2, $service->getLogs());
32
33
        $log = current($service->getLogs());
34
        $this->assertInstanceOf(LogFile::class, $log);
35
    }
36
37
    /**
38
     * Take really last log.
39
     */
40 View Code Duplication
    public function testLastLog()
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...
41
    {
42
        /** @var LogService $service */
43
        $service = $this->container->get(LogService::class);
44
45
        $this->assertEmpty($service->lastLog());
46
47
        $snapshot = $this->makeSnapshot('error', 123);
48
        $snapshot->report();
49
50
        /** @var LogFile $last */
51
        $last = $service->lastLog();
52
53
        $this->assertNotEmpty($last);
54
        $this->assertInstanceOf(LogFile::class, $last);
55
56
        $this->get('/controller/action');
57
58
        /** @var LogFile $last */
59
        $last2 = $service->lastLog();
60
        $this->assertNotEmpty($last2);
61
62
        $this->assertNotEquals($last->name(), $last2->name());
63
    }
64
65
    /**
66
     * Get log by name is really what we want
67
     */
68 View Code Duplication
    public function testGetLogByName()
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...
69
    {
70
        /** @var LogService $service */
71
        $service = $this->container->get(LogService::class);
72
73
        $snapshot = $this->makeSnapshot('error', 123);
74
        $snapshot->report();
75
76
        $this->assertEmpty($service->getLogByName('some-name'));
77
78
        /** @var LogFile $last */
79
        $last = $service->lastLog();
80
        $this->assertNotEmpty($last);
81
82
        $log = $service->getLogByName($last->name());
83
84
        $this->assertNotEmpty($log);
85
        $this->assertInstanceOf(LogFile::class, $log);
86
87
        $this->assertEquals($last->name(), $log->name());
88
    }
89
90
    /**
91
     * Remove all logs
92
     */
93 View Code Duplication
    public function testRemoveAll()
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...
94
    {
95
        /** @var LogService $service */
96
        $service = $this->container->get(LogService::class);
97
98
        $this->assertEmpty($service->getLogs());
99
100
        $snapshot = $this->makeSnapshot('error', 123);
101
        $snapshot->report();
102
103
        $this->assertCount(1, $service->getLogs());
104
105
        $this->get('/controller/action');
106
        $this->assertCount(2, $service->getLogs());
107
108
        $service->removeAll();
109
110
        $this->assertEmpty($service->getLogs());
111
    }
112
113
    /**
114
     * Remove
115
     */
116 View Code Duplication
    public function testRemove()
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...
117
    {
118
        /** @var LogService $service */
119
        $service = $this->container->get(LogService::class);
120
121
        $this->assertEmpty($service->getLogs());
122
123
        $snapshot = $this->makeSnapshot('error', 123);
124
        $snapshot->report();
125
126
        $this->assertCount(1, $service->getLogs());
127
128
        /** @var LogFile $last */
129
        $last = $service->lastLog();
130
        $this->assertNotEmpty($last);
131
132
        $service->removeLog(new LogFile('some-name'));
133
134
        $this->assertCount(1, $service->getLogs());
135
136
        $service->removeLog($last);
137
138
        $this->assertEmpty($service->getLogs());
139
    }
140
}