|
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 testReportFromString(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$contents = file_get_contents( |
|
28
|
|
|
__DIR__ . '/../Fixture/report_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.17 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.1e DAV/2 PHP/5.4.17', |
|
42
|
|
|
'user_agent_string' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36', |
|
43
|
|
|
'locale' => 'en', |
|
44
|
|
|
'configuration_storage' => true, |
|
45
|
|
|
'php_version' => '5.2.2', |
|
46
|
|
|
'exception_type' => null, |
|
47
|
|
|
], $tags); |
|
48
|
|
|
$this->assertEquals((object) [ |
|
49
|
|
|
'os' => (object) ['name' => 'Windows'], |
|
50
|
|
|
'browser' => (object) [ |
|
51
|
|
|
'name' => 'FIREFOX', |
|
52
|
|
|
'version' => '17.5', |
|
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->assertTrue($report->hasUserFeedback()); |
|
60
|
|
|
$this->assertSame('<script>test steps', $report->getUserFeedback()); |
|
61
|
|
|
$this->assertEquals([ |
|
62
|
|
|
[ |
|
63
|
|
|
'sentry.interfaces.Message' => $message, |
|
64
|
|
|
'release' => '4.5.4.1deb2ubuntu2', |
|
65
|
|
|
'platform' => 'javascript', |
|
66
|
|
|
'timestamp' => $report->getTimestampUTC(), |
|
67
|
|
|
'tags' => $tags, |
|
68
|
|
|
'contexts' => $contexts, |
|
69
|
|
|
'extra' => $extras, |
|
70
|
|
|
'user' => $user, |
|
71
|
|
|
'exception' => [ |
|
72
|
|
|
'values' => [ |
|
73
|
|
|
(object) [ |
|
74
|
|
|
'type' => 'ReferenceError', |
|
75
|
|
|
'value' => 'a is not defined', |
|
76
|
|
|
'stacktrace' => (object) [ |
|
77
|
|
|
'frames' => [ |
|
78
|
|
|
[ |
|
79
|
|
|
'platform' => 'javascript', |
|
80
|
|
|
'function' => 'PMA_exception', |
|
81
|
|
|
'lineno' => 312, |
|
82
|
|
|
'colno' => 5, |
|
83
|
|
|
'abs_path' => '', |
|
84
|
|
|
'filename' => '', |
|
85
|
|
|
], |
|
86
|
|
|
[ |
|
87
|
|
|
'platform' => 'javascript', |
|
88
|
|
|
'function' => 'new_func', |
|
89
|
|
|
'lineno' => 257, |
|
90
|
|
|
'colno' => 33, |
|
91
|
|
|
'abs_path' => '', |
|
92
|
|
|
'filename' => '', |
|
93
|
|
|
], |
|
94
|
|
|
], |
|
95
|
|
|
], |
|
96
|
|
|
], |
|
97
|
|
|
], |
|
98
|
|
|
], |
|
99
|
|
|
'message' => 'a is not defined', |
|
100
|
|
|
'culprit' => 'tbl_relation.php', |
|
101
|
|
|
'event_id' => $report->getEventId(), |
|
102
|
|
|
], |
|
103
|
|
|
], $reports); |
|
104
|
|
|
$this->assertEquals([ |
|
105
|
|
|
'sentry.interfaces.Message' => $message, |
|
106
|
|
|
'release' => '4.5.4.1deb2ubuntu2', |
|
107
|
|
|
'platform' => 'javascript', |
|
108
|
|
|
'timestamp' => $report->getTimestampUTC(), |
|
109
|
|
|
'tags' => $tags, |
|
110
|
|
|
'contexts' => $contexts, |
|
111
|
|
|
'extra' => $extras, |
|
112
|
|
|
'user' => $user, |
|
113
|
|
|
], $toJson); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|