Re: Testing a controller method

2009-01-19 Thread mark_story

You don't test private methods.  You test your public interface, and
by testing your public interface your implementation is also tested.
As far as testing controllers I wrote a somewhat lenghty post on it

http://mark-story.com/posts/view/testing-cakephp-controllers-the-hard-way

As for testing email component, I almost always do this with a Mock
object so that I can avoid any potential emails being sent by running
the test suite, and to allow for better unit separation.  Using mocks
is just a good practice to get into as well.

-Mark

On Jan 18, 8:28 am, Fran Iglesias  wrote:
> Hi,
>
> I'm trying to write a test case for a private method in a controller.  
> This controller uses the Email component.
>
> The method purpose is to send notifications via email to users.
>
> http://code.assembla.com/milhojas/subversion/nodes/dev/app/controller...
>
> I want to test if the message contains all data in the proper format.
>
> The test case, tries to send the email in debug delivery mode and  
> compares the expected message to the Message.Email.messsage session  
> variable.
>
> http://code.assembla.com/milhojas/subversion/nodes/dev/app/tests/case...
>
> The problem is that the Email component fails when trying to set a  
> flash message (EmailComponent line 767) beacause Email->Session  
> component is not an object. This only happens in the test context.
>
> So, my question is: what preparations have I to do in order to run  
> this test?
>
> Thank you.
> --
> Fran Iglesias
> fran...@buabua.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Testing a controller method

2009-01-18 Thread Fran Iglesias

Hi,

I'm trying to write a test case for a private method in a controller.  
This controller uses the Email component.

The method purpose is to send notifications via email to users.

http://code.assembla.com/milhojas/subversion/nodes/dev/app/controllers/users_controller.php#ln292

I want to test if the message contains all data in the proper format.

The test case, tries to send the email in debug delivery mode and  
compares the expected message to the Message.Email.messsage session  
variable.

http://code.assembla.com/milhojas/subversion/nodes/dev/app/tests/cases/controllers/users_controller.test.php#ln81

The problem is that the Email component fails when trying to set a  
flash message (EmailComponent line 767) beacause Email->Session  
component is not an object. This only happens in the test context.

So, my question is: what preparations have I to do in order to run  
this test?

Thank you.
--
Fran Iglesias
fran...@buabua.com





--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---