开发者

Testing for cakeError() being thrown

开发者 https://www.devze.com 2023-02-28 02:10 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号