Timeline for PHPUnit assert that an exception was thrown?
Current License: CC BY-SA 3.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 20, 2017 at 11:19 | history | edited | Farid Movsumov | CC BY-SA 3.0 |
added 2 characters in body
|
Apr 13, 2016 at 6:50 | history | edited | Farid Movsumov | CC BY-SA 3.0 |
added 4 characters in body
|
S Mar 7, 2016 at 16:36 | history | suggested | clami219 | CC BY-SA 3.0 |
Improved code in order not to catch fail function
|
Mar 7, 2016 at 15:08 | review | Suggested edits | |||
S Mar 7, 2016 at 16:36 | |||||
May 4, 2015 at 13:55 | comment | added | spyle |
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){}
|
|
Apr 9, 2015 at 21:53 | comment | added | Twifty |
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.
|
|
Mar 13, 2015 at 7:33 | history | edited | Farid Movsumov | CC BY-SA 3.0 |
added 26 characters in body
|
Apr 22, 2014 at 20:41 | comment | added | Frank Farmer |
@ken you're probably right. The call to fail probably belongs after the catch block, not inside the try.
|
|
Apr 16, 2014 at 21:33 | comment | added | ken |
$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".
|
|
Feb 27, 2014 at 8:36 | history | edited | Farid Movsumov | CC BY-SA 3.0 |
added 4 characters in body
|
Feb 27, 2014 at 8:30 | history | answered | Farid Movsumov | CC BY-SA 3.0 |