SnapshotRecordTest::testSuppress()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 8.72
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Spiral\Tests\Snapshotter\AggregationHandler\Database;
4
5
use Spiral\Snapshotter\AggregationHandler\Database\IncidentRecord;
6
use Spiral\Tests\BaseTest;
7
8
class SnapshotRecordTest extends BaseTest
9
{
10
    public function testSuppressionState()
11
    {
12
        $snapshot = $this->makeSnapshot('message', 123);
13
        $record = $this->handleSnapshot($snapshot, true);
14
15
        $this->assertFalse($record->isSuppressionEnabled());
16
17
        $record->setSuppression(true);
18
        $this->assertTrue($record->isSuppressionEnabled());
19
20
        $record->setSuppression(false);
21
        $this->assertFalse($record->isSuppressionEnabled());
22
    }
23
24
    public function testSuppress()
25
    {
26
        $snapshot = $this->makeSnapshot('message', 123);
27
28
        $this->handleSnapshot($snapshot, true);
29
        $record = $this->handleSnapshot($snapshot, true);
30
31
        $this->assertEquals(2, $record->count_occurred);
32
        $this->assertCount(1, $record->getIncidentsHistory());
33
34
        /** @var IncidentRecord $incident */
35
        $incident = iterator_to_array($record->getIncidentsHistory())[0];
36
37
        $this->assertNotEmpty($incident);
38
        $this->assertNotEmpty($incident->getExceptionSource());
39
        $this->assertTrue($incident->status->isStored());
40
41
        //Suppress new history record
42
        $record->setSuppression(true);
43
        $record->save();
44
45
        $record = $this->handleSnapshot($snapshot, true);
46
47
        $this->assertEquals(3, $record->count_occurred);
48
        $this->assertCount(2, $record->getIncidentsHistory());
49
50
        $incident = iterator_to_array($record->getIncidentsHistory())[0];
51
52
        $this->assertNotEmpty($incident);
53
        $this->assertNotEmpty($incident->getExceptionSource());
54
        $this->assertTrue($incident->status->isStored());
55
56
        $incident = iterator_to_array($record->getIncidentsHistory())[1];
57
58
        $this->assertNotEmpty($incident);
59
        $this->assertEmpty($incident->getExceptionSource());
60
        $this->assertFalse($incident->status->isStored());
61
        $this->assertTrue($incident->status->isSuppressed());
62
63
        //Don't suppress new history record
64
        $record->setSuppression(false);
65
        $record->save();
66
67
        $record = $this->handleSnapshot($snapshot, true);
68
69
        $this->assertEquals(4, $record->count_occurred);
70
        $this->assertCount(3, $record->getIncidentsHistory());
71
72
        $incident = iterator_to_array($record->getIncidentsHistory())[0];
73
74
        $this->assertNotEmpty($incident);
75
        $this->assertNotEmpty($incident->getExceptionSource());
76
        $this->assertTrue($incident->status->isStored());
77
78
        $incident = iterator_to_array($record->getIncidentsHistory())[1];
79
80
        $this->assertNotEmpty($incident);
81
        $this->assertEmpty($incident->getExceptionSource());
82
        $this->assertFalse($incident->status->isStored());
83
        $this->assertTrue($incident->status->isSuppressed());
84
85
        $incident = iterator_to_array($record->getIncidentsHistory())[2];
86
87
        $this->assertNotEmpty($incident);
88
        $this->assertNotEmpty($incident->getExceptionSource());
89
        $this->assertTrue($incident->status->isStored());
90
    }
91
}