1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spiral\Tests\Snapshotter; |
4
|
|
|
|
5
|
|
|
use Spiral\Snapshotter\AggregationHandler; |
6
|
|
|
use Spiral\Snapshotter\AggregationHandler\Database\IncidentRecord; |
7
|
|
|
use Spiral\Snapshotter\AggregationHandler\Database\SnapshotRecord; |
8
|
|
|
use Spiral\Tests\BaseTest; |
9
|
|
|
|
10
|
|
|
class AggregationHandlerTest extends BaseTest |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Snapshot and incident record are successfully created |
14
|
|
|
*/ |
15
|
|
|
public function testFirstOccurrence() |
16
|
|
|
{ |
17
|
|
|
$snapshot = $this->makeSnapshot('custom error', 777); |
18
|
|
|
$this->assertSame(0, $this->orm->source(SnapshotRecord::class)->count()); |
19
|
|
|
|
20
|
|
|
$this->handleSnapshot($snapshot, true); |
21
|
|
|
$this->assertSame(1, $this->orm->source(SnapshotRecord::class)->count()); |
22
|
|
|
$this->assertSame(1, $this->orm->source(IncidentRecord::class)->count()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Snapshot has several incidents |
27
|
|
|
*/ |
28
|
|
|
public function testSecondOccurrence() |
29
|
|
|
{ |
30
|
|
|
$snapshot = $this->makeSnapshot('custom error', 777); |
31
|
|
|
$this->assertSame(0, $this->orm->source(SnapshotRecord::class)->count()); |
32
|
|
|
|
33
|
|
|
$snapshotRecord = $this->handleSnapshot($snapshot, true); |
34
|
|
|
$this->assertSame(1, $this->orm->source(SnapshotRecord::class)->count()); |
35
|
|
|
$this->assertSame(1, $this->orm->source(IncidentRecord::class)->count()); |
36
|
|
|
|
37
|
|
|
//After first incident history is empty |
38
|
|
|
$this->assertCount(0, $snapshotRecord->getIncidentsHistory()); |
39
|
|
|
|
40
|
|
|
$snapshotRecord = $this->handleSnapshot($snapshot, true); |
41
|
|
|
$this->assertSame(1, $this->orm->source(SnapshotRecord::class)->count()); |
42
|
|
|
$this->assertSame(2, $this->orm->source(IncidentRecord::class)->count()); |
43
|
|
|
$this->assertCount(1, $snapshotRecord->getIncidentsHistory()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Several snapshots occurred |
48
|
|
|
* Snapshots successfully aggregated by snapshot teaser. |
49
|
|
|
* Format: "{exception class}: {message} in {file} at line {line}" |
50
|
|
|
*/ |
51
|
|
|
public function testAnotherOccurrence() |
52
|
|
|
{ |
53
|
|
|
$snapshot = $this->makeSnapshot('custom error', 777); |
54
|
|
|
$this->assertSame(0, $this->orm->source(SnapshotRecord::class)->count()); |
55
|
|
|
|
56
|
|
|
$this->handleSnapshot($snapshot, true); |
57
|
|
|
$this->assertSame(1, $this->orm->source(SnapshotRecord::class)->count()); |
58
|
|
|
$this->assertSame(1, $this->orm->source(IncidentRecord::class)->count()); |
59
|
|
|
|
60
|
|
|
$snapshot2 = $this->makeSnapshot('another custom error', 777); |
61
|
|
|
|
62
|
|
|
$this->handleSnapshot($snapshot2, true); |
63
|
|
|
$this->assertSame(2, $this->orm->source(SnapshotRecord::class)->count()); |
64
|
|
|
$this->assertSame(2, $this->orm->source(IncidentRecord::class)->count()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Incident data is correct |
69
|
|
|
*/ |
70
|
|
|
public function testIncidentIntegrity() |
71
|
|
|
{ |
72
|
|
|
$snapshot = $this->makeSnapshot('custom error', 777); |
73
|
|
|
$this->assertSame(0, $this->orm->source(SnapshotRecord::class)->count()); |
74
|
|
|
|
75
|
|
|
$snapshotRecord = $this->handleSnapshot($snapshot, true); |
76
|
|
|
|
77
|
|
|
/* |
78
|
|
|
* Can't test $snapshot->render() because it renders on demand so content is not equal by nature |
79
|
|
|
*/ |
80
|
|
|
$lastIncident = $snapshotRecord->getLastIncident(); |
81
|
|
|
$this->assertNotEmpty($lastIncident); |
82
|
|
|
|
83
|
|
|
$this->assertEquals(true, $lastIncident->status->isLast()); |
84
|
|
|
|
85
|
|
|
$this->assertEquals( |
86
|
|
|
get_class($snapshot->getException()), |
87
|
|
|
$lastIncident->getExceptionClass() |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$this->assertEquals( |
91
|
|
|
$snapshot->getException()->getMessage(), |
92
|
|
|
$lastIncident->getExceptionMessage() |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
$this->assertEquals( |
96
|
|
|
$snapshot->getMessage(), |
97
|
|
|
$lastIncident->getExceptionTeaser() |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
$this->assertEquals( |
101
|
|
|
AggregationHandler\Services\SnapshotService::makeHash($snapshot), |
102
|
|
|
$lastIncident->getExceptionHash() |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$this->assertEquals( |
106
|
|
|
$snapshot->getException()->getCode(), |
107
|
|
|
$lastIncident->getExceptionCode() |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$this->assertEquals( |
111
|
|
|
$snapshot->getException()->getFile(), |
112
|
|
|
$lastIncident->getExceptionFile() |
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
$this->assertEquals( |
116
|
|
|
$snapshot->getException()->getLine(), |
117
|
|
|
$lastIncident->getExceptionLine() |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
} |