On Jan/02, AD7six wrote:
> 
> 
> On Dec 28 2011, 4:22 pm, Matteo Landi <[email protected]> wrote:
> > Hi everybody,
> >
> > I have a custom exception handler for all the exceptions raised inside
> > controllers; when I run the controllers' testsuite, I noticed that 
> > exceptions
> > are propagated to the tests instead of being handled by my handler. Is this 
> > the
> > normal behaviour? What if I want to make some assertions on the output of 
> > the
> > exception produced by the handler? Is this out of the scope of 
> > ControllerTest
> > logic or is it ok to test that kind of things inside controller tests?
> 
> It is a bad idea to do what you ask, but if you want to know how -
> just use the source
> https://github.com/cakephp/cakephp/blob/master/lib/Cake/Test/Case/Error/ErrorHandlerTest.php
> 
> Your tests should only be testing for (expected) exceptions being
> thrown - If you want to test your  exception handler logic - you'd do
> that separately, e.g. see link.

That makes sense.

> 
> What does the exception logic that is being missed do? The question
> implies you are misusing exceptions.
> 

Some more context should help: I'm working on a REST application in which,
before switching to exceptions, each time an error was returned, I used to
create arrays objects containing such error messages and then let the _View_
transform the PHP object into a JSON or XML one.

Now with exceptions it seems to me that the controller logic is simplified
a lot: instead of all the <<if () return array('error' => )>> logic, I can
simply call the the method interest and let it throw the specific exception if
needed; moreover, I can use a custom exception handler able to understand the
kind or request (JSON or XML) and create the well-formatted error page.

Am I doing something wrong or is this a good way to do things? Thanks for the
advices.


Matteo

> AD
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/cake-php
> 

-- 
http://www.matteolandi.net

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to