I try to see if an exception is thrown from my controller
In my controller I have a "throw new \ RuntimeException"
In my test, if I put setExpectedException ('RuntimeException'), my assertion fails if the full test fails
What should I do?
class myController extends AbstractActionController {
public function indexAction() {
...
throw new \RuntimeException;
}
}
class myControllerTest extends AbstractHttpControllerTestCase {
public function testIndexAction() {
...
$this->setExpectedException('RuntimeException');
...
$this->dispatch('/');
}
}
Output with 'setExpectedException' :
1) ApplicationTest\Controller\myControllerTest::testIndexAction Failed asserting that exception of type "\RuntimeException" is thrown.
Output without :
1) ApplicationTest\Controller\myControllerTest::testIndexAction with data set #0 (false, '', 1) RuntimeException:
/home/bruno/public_html/jacuzzi/module/Application/src/Application/Controller/myController.php:60 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php:82 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:444 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:205 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php:118 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php:93 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:444 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:205 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:314 /home/bruno/public_html/jacuzzi/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:282 /home/bruno/public_html/jacuzzi/module/Application/test/ApplicationTest/Controller/myControllerTest.php:188
PS: I use ZF 2.4.4 and PHPUnit 4.7.8