Skip to content

Commit e83a9a4

Browse files
committed
Make E2E tests backward compatible
1 parent ad28cd3 commit e83a9a4

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

test/End2End/App/Controller/MainController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class MainController
88
{
99
public function exception(): Response
1010
{
11-
throw new \Exception('This is an intentional error');
11+
throw new \RuntimeException('This is an intentional error');
1212
}
1313
}

test/End2End/End2EndTest.php

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Sentry\State\HubInterface;
88
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
99
use Symfony\Component\HttpFoundation\Response;
10+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1011

1112
class_alias(TestCase::class, \PHPUnit_Framework_TestCase::class);
1213

@@ -26,14 +27,22 @@ protected static function getKernelClass(): string
2627

2728
public function testGet404(): void
2829
{
29-
$client = static::createClient();
30+
$client = static::createClient(['debug' => false]);
31+
32+
try {
33+
$client->request('GET', '/missing-page');
3034

31-
$client->request('GET', '/missing-page');
35+
$response = $client->getResponse();
3236

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+
}
3443

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+
}
3746

3847
$hub = $client->getContainer()->get('test.hub');
3948

@@ -45,13 +54,21 @@ public function testGet500(): void
4554
{
4655
$client = static::createClient();
4756

48-
$client->request('GET', '/exception');
57+
try {
58+
$client->request('GET', '/exception');
59+
60+
$response = $client->getResponse();
4961

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+
}
5169

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+
}
5572

5673
$hub = $client->getContainer()->get('test.hub');
5774

0 commit comments

Comments
 (0)