Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 7
    $this->fail() isn't meant to be used this way I don't think, at least not currently (PHPUnit 3.6.11); it acts as an exception itself. Using your example, if $this->fail("Expected exception not thrown") is called, then the catch block is triggered and $e->getMessage() is "Expected exception not thrown".
    – ken
    Commented Apr 16, 2014 at 21:33
  • 1
    @ken you're probably right. The call to fail probably belongs after the catch block, not inside the try. Commented Apr 22, 2014 at 20:41
  • 2
    I have to downvote because the call to fail should not be in the try block. It in itself triggers the catch block producing false results.
    – Twifty
    Commented Apr 9, 2015 at 21:53
  • 7
    I believe the reason this doesn't work well is some situation is that it's catching all exceptions with catch(Exception $e). This method works quite well for me when I try to catch specific Exceptions: try { throw new MySpecificException; $this->fail('MySpecificException not thrown'); } catch(MySpecificException $e){}
    – spyle
    Commented May 4, 2015 at 13:55