7
7
use Sentry \State \HubInterface ;
8
8
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
9
9
use Symfony \Component \HttpFoundation \Response ;
10
+ use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
10
11
11
12
class_alias (TestCase::class, \PHPUnit_Framework_TestCase::class);
12
13
@@ -26,14 +27,22 @@ protected static function getKernelClass(): string
26
27
27
28
public function testGet404 (): void
28
29
{
29
- $ client = static ::createClient ();
30
+ $ client = static ::createClient (['debug ' => false ]);
31
+
32
+ try {
33
+ $ client ->request ('GET ' , '/missing-page ' );
30
34
31
- $ client ->request ( ' GET ' , ' /missing-page ' );
35
+ $ response = $ client ->getResponse ( );
32
36
33
- $ response = $ client ->getResponse ();
37
+ $ this ->assertInstanceOf (Response::class, $ response );
38
+ $ this ->assertSame (404 , $ response ->getStatusCode (), $ response ->getContent ());
39
+ } catch (\Throwable $ exception ) {
40
+ if (! $ exception instanceof NotFoundHttpException) {
41
+ throw $ exception ;
42
+ }
34
43
35
- $ this ->assertInstanceOf (Response::class , $ response );
36
- $ this -> assertSame ( 404 , $ response -> getStatusCode (), $ response -> getContent ());
44
+ $ this ->assertSame ( ' No route found for "GET /missing-page" ' , $ exception -> getMessage () );
45
+ }
37
46
38
47
$ hub = $ client ->getContainer ()->get ('test.hub ' );
39
48
@@ -45,13 +54,21 @@ public function testGet500(): void
45
54
{
46
55
$ client = static ::createClient ();
47
56
48
- $ client ->request ('GET ' , '/exception ' );
57
+ try {
58
+ $ client ->request ('GET ' , '/exception ' );
59
+
60
+ $ response = $ client ->getResponse ();
49
61
50
- $ response = $ client ->getResponse ();
62
+ $ this ->assertInstanceOf (Response::class, $ response );
63
+ $ this ->assertSame (500 , $ response ->getStatusCode (), $ response ->getContent ());
64
+ $ this ->assertContains ('intentional error ' , $ response ->getContent ());
65
+ } catch (\Throwable $ exception ) {
66
+ if (! $ exception instanceof \RuntimeException) {
67
+ throw $ exception ;
68
+ }
51
69
52
- $ this ->assertInstanceOf (Response::class, $ response );
53
- $ this ->assertSame (500 , $ response ->getStatusCode (), $ response ->getContent ());
54
- $ this ->assertContains ('intentional error ' , $ response ->getContent ());
70
+ $ this ->assertSame ('This is an intentional error ' , $ exception ->getMessage ());
71
+ }
55
72
56
73
$ hub = $ client ->getContainer ()->get ('test.hub ' );
57
74
0 commit comments