1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Test; |
4
|
|
|
|
5
|
|
|
use App\Report; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
use function file_get_contents; |
9
|
|
|
use function json_decode; |
10
|
|
|
|
11
|
|
|
class ReportTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testReportFromObject(): void |
14
|
|
|
{ |
15
|
|
|
$contents = file_get_contents( |
16
|
|
|
__DIR__ . '/../Fixture/report_js.json' |
17
|
|
|
); |
18
|
|
|
$obj = json_decode($contents); |
19
|
|
|
$report1 = Report::fromObject($obj); |
20
|
|
|
$report2 = Report::fromString($contents); |
21
|
|
|
|
22
|
|
|
$this->assertEquals($report1, $report2); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testReportRoutingSystem(): void |
26
|
|
|
{ |
27
|
|
|
$contents = file_get_contents( |
28
|
|
|
__DIR__ . '/../Fixture/report_issue_16853_js.json' |
29
|
|
|
); |
30
|
|
|
$report = Report::fromString($contents); |
31
|
|
|
|
32
|
|
|
$tags = $report->getTags(); |
33
|
|
|
$contexts = $report->getContexts(); |
34
|
|
|
$extras = $report->getExtras(); |
35
|
|
|
$reports = $report->getReports(); |
36
|
|
|
$user = $report->getUser(); |
37
|
|
|
$message = $report->getUserMessage(); |
38
|
|
|
$toJson = $report->toJson(); |
39
|
|
|
|
40
|
|
|
$this->assertEquals((object) [ |
41
|
|
|
'server_software' => 'nginx/1.14.2', |
42
|
|
|
'user_agent_string' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0', |
43
|
|
|
'locale' => 'en', |
44
|
|
|
'configuration_storage' => false, |
45
|
|
|
'php_version' => '7.4.14', |
46
|
|
|
'exception_type' => 'js', |
47
|
|
|
], $tags); |
48
|
|
|
$this->assertEquals((object) [ |
49
|
|
|
'os' => (object) ['name' => 'Win'], |
50
|
|
|
'browser' => (object) [ |
51
|
|
|
'name' => 'FIREFOX', |
52
|
|
|
'version' => '90.0', |
53
|
|
|
], |
54
|
|
|
], $contexts); |
55
|
|
|
$this->assertEquals((object) [], $extras); |
56
|
|
|
$this->assertEquals((object) ['message' => ''], $message); |
57
|
|
|
$this->assertEquals((object) ['ip_address' => '0.0.0.0'], $user); |
58
|
|
|
$this->assertFalse($report->isMultiReports()); |
59
|
|
|
$this->assertFalse($report->hasUserFeedback()); |
60
|
|
|
$this->assertEquals([ |
61
|
|
|
[ |
62
|
|
|
'sentry.interfaces.Message' => $message, |
63
|
|
|
'release' => '5.2.0-dev', |
64
|
|
|
'dist' => '5.2.0-dev', |
65
|
|
|
'platform' => 'javascript', |
66
|
|
|
'environment' => 'development', |
67
|
|
|
'transaction' => '/database/designer', |
68
|
|
|
'timestamp' => $report->getTimestampUTC(), |
69
|
|
|
'tags' => $tags, |
70
|
|
|
'contexts' => $contexts, |
71
|
|
|
'extra' => $extras, |
72
|
|
|
'user' => $user, |
73
|
|
|
'exception' => [ |
74
|
|
|
'values' => [ |
75
|
|
|
(object) [ |
76
|
|
|
'type' => 'TypeError', |
77
|
|
|
'value' => 'can\'t access property "transaction", db is null', |
78
|
|
|
'stacktrace' => (object) [ |
79
|
|
|
'frames' => $reports[0]['exception']['values'][0]->stacktrace->frames, |
80
|
|
|
], |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
], |
84
|
|
|
'message' => 'can\'t access property "transaction", db is null', |
85
|
|
|
'culprit' => 'index.php', |
86
|
|
|
'event_id' => $report->getEventId(), |
87
|
|
|
], |
88
|
|
|
], $reports); |
89
|
|
|
$this->assertEquals([ |
90
|
|
|
'sentry.interfaces.Message' => $message, |
91
|
|
|
'release' => '5.2.0-dev', |
92
|
|
|
'dist' => '5.2.0-dev', |
93
|
|
|
'platform' => 'javascript', |
94
|
|
|
'environment' => 'development', |
95
|
|
|
'transaction' => '/database/designer', |
96
|
|
|
'timestamp' => $report->getTimestampUTC(), |
97
|
|
|
'tags' => $tags, |
98
|
|
|
'contexts' => $contexts, |
99
|
|
|
'extra' => $extras, |
100
|
|
|
'user' => $user, |
101
|
|
|
], $toJson); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testReportFromString(): void |
105
|
|
|
{ |
106
|
|
|
$contents = file_get_contents( |
107
|
|
|
__DIR__ . '/../Fixture/report_js.json' |
108
|
|
|
); |
109
|
|
|
$report = Report::fromString($contents); |
110
|
|
|
|
111
|
|
|
$tags = $report->getTags(); |
112
|
|
|
$contexts = $report->getContexts(); |
113
|
|
|
$extras = $report->getExtras(); |
114
|
|
|
$reports = $report->getReports(); |
115
|
|
|
$user = $report->getUser(); |
116
|
|
|
$message = $report->getUserMessage(); |
117
|
|
|
$toJson = $report->toJson(); |
118
|
|
|
|
119
|
|
|
$this->assertEquals((object) [ |
120
|
|
|
'server_software' => 'NginX/1.17 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.1e DAV/2 PHP/5.4.17', |
121
|
|
|
'user_agent_string' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36', |
122
|
|
|
'locale' => 'en', |
123
|
|
|
'configuration_storage' => true, |
124
|
|
|
'php_version' => '5.2.2', |
125
|
|
|
'exception_type' => null, |
126
|
|
|
], $tags); |
127
|
|
|
$this->assertEquals((object) [ |
128
|
|
|
'os' => (object) ['name' => 'Windows'], |
129
|
|
|
'browser' => (object) [ |
130
|
|
|
'name' => 'FIREFOX', |
131
|
|
|
'version' => '17.5', |
132
|
|
|
], |
133
|
|
|
], $contexts); |
134
|
|
|
$this->assertEquals((object) [], $extras); |
135
|
|
|
$this->assertEquals((object) ['message' => ''], $message); |
136
|
|
|
$this->assertEquals((object) ['ip_address' => '0.0.0.0'], $user); |
137
|
|
|
$this->assertFalse($report->isMultiReports()); |
138
|
|
|
$this->assertTrue($report->hasUserFeedback()); |
139
|
|
|
$this->assertSame('<script>test steps', $report->getUserFeedback()); |
140
|
|
|
$this->assertEquals([ |
141
|
|
|
[ |
142
|
|
|
'sentry.interfaces.Message' => $message, |
143
|
|
|
'release' => '4.5.4.1', |
144
|
|
|
'dist' => '4.5.4.1deb2ubuntu2', |
145
|
|
|
'platform' => 'javascript', |
146
|
|
|
'environment' => 'production', |
147
|
|
|
'timestamp' => $report->getTimestampUTC(), |
148
|
|
|
'tags' => $tags, |
149
|
|
|
'contexts' => $contexts, |
150
|
|
|
'extra' => $extras, |
151
|
|
|
'user' => $user, |
152
|
|
|
'exception' => [ |
153
|
|
|
'values' => [ |
154
|
|
|
(object) [ |
155
|
|
|
'type' => 'ReferenceError', |
156
|
|
|
'value' => 'a is not defined', |
157
|
|
|
'stacktrace' => (object) [ |
158
|
|
|
'frames' => [ |
159
|
|
|
[ |
160
|
|
|
'platform' => 'javascript', |
161
|
|
|
'function' => 'PMA_exception', |
162
|
|
|
'lineno' => 312, |
163
|
|
|
'colno' => 5, |
164
|
|
|
'abs_path' => '', |
165
|
|
|
'filename' => '', |
166
|
|
|
], |
167
|
|
|
[ |
168
|
|
|
'platform' => 'javascript', |
169
|
|
|
'function' => 'new_func', |
170
|
|
|
'lineno' => 257, |
171
|
|
|
'colno' => 33, |
172
|
|
|
'abs_path' => '', |
173
|
|
|
'filename' => '', |
174
|
|
|
], |
175
|
|
|
], |
176
|
|
|
], |
177
|
|
|
], |
178
|
|
|
], |
179
|
|
|
], |
180
|
|
|
'message' => 'a is not defined', |
181
|
|
|
'culprit' => 'tbl_relation.php', |
182
|
|
|
'event_id' => $report->getEventId(), |
183
|
|
|
], |
184
|
|
|
], $reports); |
185
|
|
|
$this->assertEquals([ |
186
|
|
|
'sentry.interfaces.Message' => $message, |
187
|
|
|
'release' => '4.5.4.1', |
188
|
|
|
'dist' => '4.5.4.1deb2ubuntu2', |
189
|
|
|
'platform' => 'javascript', |
190
|
|
|
'timestamp' => $report->getTimestampUTC(), |
191
|
|
|
'tags' => $tags, |
192
|
|
|
'contexts' => $contexts, |
193
|
|
|
'extra' => $extras, |
194
|
|
|
'user' => $user, |
195
|
|
|
'environment' => 'production', |
196
|
|
|
], $toJson); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|