Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is an old question but I was struggling with this today and couldn't find a good answer anywhere else so I'll go ahead and post what I did to solve this problem. The answer is actually really simple.</p> <p>Point your dispatch to an action that will result in a thrown exception.</p> <p>My application throws an error when a get request is made to a JSON end point, so I used one of those to test this.</p> <pre><code> /** * @covers ErrorController::errorAction */ public function testErrorAction500() { /** * Requesting a page that doesn't exist returns the proper error message */ $this-&gt;dispatch('/my-json-controller/json-end-point'); $body = $this-&gt;getResponse()-&gt;getBody(); $this-&gt;assertResponseCode('500'); $this-&gt;assertContains('Application error',$body); } </code></pre> <p>Alternatively, if you don't mind having an action just for testing, you could just create an action that only throws an error and point to that action in your unit test.</p> <pre><code>public function errorAction() { throw new Exception('You should not be here'); } </code></pre> <p>Then your test would look like this:</p> <pre><code> /** * @covers ErrorController::errorAction */ public function testErrorAction500() { /** * Requesting a page that doesn't exist returns the proper error message */ $this-&gt;dispatch('/my-error-controller/error'); $body = $this-&gt;getResponse()-&gt;getBody(); $this-&gt;assertResponseCode('500'); $this-&gt;assertContains('Application error',$body); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload