SnapshotRecordTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 84
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSuppressionState() 0 13 1
B testSuppress() 0 67 1
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
}