|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\HttpFoundation\Request;
|
16 | 16 | use Symfony\Component\HttpFoundation\Response;
|
| 17 | +use Symfony\Component\HttpKernel\Exception\HttpException; |
17 | 18 | use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
|
18 | 19 |
|
19 | 20 | /**
|
@@ -53,11 +54,20 @@ public function testRenderWithUnknownRenderer()
|
53 | 54 |
|
54 | 55 | public function testDeliverWithUnsuccessfulResponse()
|
55 | 56 | {
|
56 |
| - $this->expectException('RuntimeException'); |
57 |
| - $this->expectExceptionMessage('Error when rendering "http://localhost/" (Status code is 404).'); |
58 | 57 | $handler = $this->getHandler($this->returnValue(new Response('foo', 404)));
|
59 |
| - |
60 |
| - $handler->render('/', 'foo'); |
| 58 | + try { |
| 59 | + $handler->render('/', 'foo'); |
| 60 | + $this->fail('->render() throws a \RuntimeException exception if response is not successful'); |
| 61 | + } catch (\Exception $e) { |
| 62 | + $this->assertInstanceOf('\RuntimeException', $e); |
| 63 | + $this->assertEquals(0, $e->getCode()); |
| 64 | + $this->assertEquals('Error when rendering "http://localhost/" (Status code is 404).', $e->getMessage()); |
| 65 | + |
| 66 | + $previousException = $e->getPrevious(); |
| 67 | + $this->assertInstanceOf(HttpException::class, $previousException); |
| 68 | + $this->assertEquals(404, $previousException->getStatusCode()); |
| 69 | + $this->assertEquals(0, $previousException->getCode()); |
| 70 | + } |
61 | 71 | }
|
62 | 72 |
|
63 | 73 | public function testRender()
|
|
0 commit comments