Re: Unit Testing Controller using fixture in test_suit config

2008-03-08 Thread Jason

I've spent the last two days working with this and whilst I have had
some success I eventually came to the conclusion that it's not really
the best way to test controllers, at least not for me. I don't think
that's the way they intended it to be used and I'm starting to agree
with them. Either that or they've just beaten me down *until* I agree
with them...

Here's one way I got it to use the test suite settings in my
controller:

function testTest()
{
$controller = new MembersController();
$controller-Member = new MemberTest();
$controller-MemberProfile = new MemberProfileTest();
$controller-Project = new ProjectTest();

$controller-get(1);

debug($controller-viewVars);

/* assert things here */
}

It's really naff which is why I eventually decided on another course
of action, but it does force my controller to use the test suite
Models (obviously you need to declare those test Models somewhere so
that they use the test suite tables set up by your fixtures).
$controller-viewVars should contain any of the things which have been
set in your Controller for passing to the View, and I assume that's
what you'd be wanting to inspect.

Trouble is that this isn't strictly unit testing since you're not
testing the Controller in isolation, you're testing the Controller and
the Model (and the View if you use testAction). The way I'm now trying
to work it is to put a lot of the logic from my Controllers into the
Model so it can be tested. To be honest I should have done it that way
in the first place since things like login validation for passwords
and the like probably belong there. That means I can test more of the
application with the test suite doing what it is best at and testing
of the Controllers is much less of an issue.

I suggest that if you want to test the Controller then you create
mocks for your Models, i.e. Models that don't really interact with the
database but have predefined data in them. That isolates the
Controller for testing and means the database is no longer an issue.
Even then you may have problems with Model associations should you
want to test anything that uses that.

Probably not what you wanted to hear and if anyone else does have a
good (and simple - if it ain't simple then people won't do it) way of
doing it then I'd be very interested. But for now I rather write code
than struggle to actually test it in a repeatable way!


Jason.


On Mar 6, 1:16 am, Micro [EMAIL PROTECTED] wrote:
 Does anyone know how to test controller in CakePhp 1.2 using the
 test_suit controller?  I am using the testAction function to test my
 controller.  However, it goes to the non-test_suit database.  Any idea?

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



Unit Testing Controller using fixture in test_suit config

2008-03-05 Thread Micro

Does anyone know how to test controller in CakePhp 1.2 using the
test_suit controller?  I am using the testAction function to test my
controller.  However, it goes to the non-test_suit database.  Any idea?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---