Fixes for problems using PHPUnit and Zend Framework

When a user accesses / user / checks without the correct message parameters, my Zend application throws a zend exception. (I get the standard error message, framed in my layout). This is intentional.

Now I am trying to test this behavior using PHPUnit. Here is my test:

/** * @expectedException Zend_Exception */ public function testEmptyUserValidationParametersCauseException() { $this->dispatch('/user/validate'); } 

When I run the test, I get a message stating that it failed "Expected Zend_Exception". Any ideas?

I have other tests in the file that work fine ...

Thanks!

+6
source share
2 answers

The Zend_Controller_Plugin_ErrorHandler plugin handles exceptions for you, and by default Error_Controller forces a redirect of 500, which may mean that the exception you are testing no longer exists. Try a unit test and see if it passes:

 public function testUnknownUserRedirectsToErrorPage() { $this->dispatch('/user/validate'); $this->assertController('error'); $this->assertAction('error'); $this->assertResponseCode('500'); } 

If this works, then it shows that by the time you create the error view, the exception will no longer exist, as it is contained in the code before the redirect.

+5
source

Well, maybe he just fails because an exception is possible?

Have you tried running the test without "@expectedException Zend_Exception"? Is there any exception?

+2
source

Source: https://habr.com/ru/post/891796/


All Articles