Testing for cakeError() being thrown
I am using Unit Testing in CakePHP 1.3. My app uses a very simple ErrorHandler as taught by the book. One of my models calls $this->cakeError('myError')
if something is wrong.
Now I want a test case for my model, that checks if - wrong data given - the error handler is properly called.
SimpleTest of开发者_如何学JAVAfers expectError()
but this seems to be made for standard PHP errors. CakePHP's error handling is a different thing, though, these errors are not caught by expectError(). If cakeError() is called in a test, the error message is rendered, rather than the test results.
How can I test for expected cakeErrors?
You could probably use a partial mock and mock the cakeError
method. Then you can use expectOnce
to assert the cakeError
method is called. See the documentation for an example and further explanations.
精彩评论