2
2
3
3
namespace Sentry \SentryBundle \Test \End2End ;
4
4
5
- use PHPUnit \Framework \TestCase ;
6
5
use Sentry \SentryBundle \Test \End2End \App \Kernel ;
7
6
use Sentry \State \HubInterface ;
8
7
use Symfony \Bundle \FrameworkBundle \Client ;
11
10
use Symfony \Component \HttpFoundation \Response ;
12
11
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
13
12
14
- class_alias (TestCase::class, \PHPUnit_Framework_TestCase::class);
15
13
if (! class_exists (KernelBrowser::class)) {
16
14
class_alias (Client::class, KernelBrowser::class);
17
15
}
@@ -21,11 +19,20 @@ class_alias(Client::class, KernelBrowser::class);
21
19
*/
22
20
class End2EndTest extends WebTestCase
23
21
{
22
+ public const SENT_EVENTS_LOG = '/tmp/sentry_e2e_test_sent_events.log ' ;
23
+
24
24
protected static function getKernelClass (): string
25
25
{
26
26
return Kernel::class;
27
27
}
28
28
29
+ protected function setUp (): void
30
+ {
31
+ parent ::setUp ();
32
+
33
+ file_put_contents (self ::SENT_EVENTS_LOG , '' );
34
+ }
35
+
29
36
public function testGet200 (): void
30
37
{
31
38
$ client = static ::createClient (['debug ' => false ]);
@@ -38,6 +45,7 @@ public function testGet200(): void
38
45
$ this ->assertSame (200 , $ response ->getStatusCode ());
39
46
40
47
$ this ->assertLastEventIdIsNotNull ($ client );
48
+ $ this ->assertEventCount (1 );
41
49
}
42
50
43
51
public function testGet200BehindFirewall (): void
@@ -52,6 +60,7 @@ public function testGet200BehindFirewall(): void
52
60
$ this ->assertSame (200 , $ response ->getStatusCode ());
53
61
54
62
$ this ->assertLastEventIdIsNotNull ($ client );
63
+ $ this ->assertEventCount (1 );
55
64
}
56
65
57
66
public function testGet200WithSubrequest (): void
@@ -66,6 +75,7 @@ public function testGet200WithSubrequest(): void
66
75
$ this ->assertSame (200 , $ response ->getStatusCode ());
67
76
68
77
$ this ->assertLastEventIdIsNotNull ($ client );
78
+ $ this ->assertEventCount (1 );
69
79
}
70
80
71
81
public function testGet404 (): void
@@ -88,6 +98,7 @@ public function testGet404(): void
88
98
}
89
99
90
100
$ this ->assertLastEventIdIsNotNull ($ client );
101
+ $ this ->assertEventCount (1 );
91
102
}
92
103
93
104
public function testGet500 (): void
@@ -111,6 +122,44 @@ public function testGet500(): void
111
122
}
112
123
113
124
$ this ->assertLastEventIdIsNotNull ($ client );
125
+ $ this ->assertEventCount (1 );
126
+ }
127
+
128
+ public function testGetFatal (): void
129
+ {
130
+ $ client = static ::createClient ();
131
+
132
+ try {
133
+ $ client ->insulate (true );
134
+ $ client ->request ('GET ' , '/fatal ' );
135
+
136
+ $ response = $ client ->getResponse ();
137
+
138
+ $ this ->assertInstanceOf (Response::class, $ response );
139
+ $ this ->assertSame (500 , $ response ->getStatusCode ());
140
+ $ this ->assertStringNotContainsString ('not happen ' , $ response ->getContent () ?: '' );
141
+ } catch (\RuntimeException $ exception ) {
142
+ $ this ->assertStringContainsStringIgnoringCase ('error ' , $ exception ->getMessage ());
143
+ $ this ->assertStringContainsStringIgnoringCase ('contains 2 abstract methods ' , $ exception ->getMessage ());
144
+ $ this ->assertStringContainsStringIgnoringCase ('MainController.php ' , $ exception ->getMessage ());
145
+ $ this ->assertStringContainsStringIgnoringCase ('eval() \'d code on line ' , $ exception ->getMessage ());
146
+ }
147
+
148
+ $ this ->assertEventCount (1 );
149
+ }
150
+
151
+ public function testNotice (): void
152
+ {
153
+ $ client = static ::createClient ();
154
+ $ client ->request ('GET ' , '/notice ' );
155
+
156
+ $ response = $ client ->getResponse ();
157
+
158
+ $ this ->assertInstanceOf (Response::class, $ response );
159
+ $ this ->assertSame (200 , $ response ->getStatusCode ());
160
+
161
+ $ this ->assertLastEventIdIsNotNull ($ client );
162
+ $ this ->assertEventCount (1 );
114
163
}
115
164
116
165
private function assertLastEventIdIsNotNull (KernelBrowser $ client ): void
@@ -123,4 +172,12 @@ private function assertLastEventIdIsNotNull(KernelBrowser $client): void
123
172
124
173
$ this ->assertNotNull ($ hub ->getLastEventId (), 'Last error not captured ' );
125
174
}
175
+
176
+ private function assertEventCount (int $ expectedCount ): void
177
+ {
178
+ $ events = file_get_contents (self ::SENT_EVENTS_LOG );
179
+ $ this ->assertNotFalse ($ events , 'Cannot read sent events log ' );
180
+ $ listOfEvents = array_filter (explode (StubTransportFactory::SEPARATOR , trim ($ events )));
181
+ $ this ->assertCount ($ expectedCount , $ listOfEvents , 'Wrong number of events sent: ' . PHP_EOL . $ events );
182
+ }
126
183
}
0 commit comments