I know the issue of testing controllers with SimpleTest has come up before but unfortunately has gone unanswered. I'm hoping that in the time that has passed it has been figured out. Testing models works fine but controllers on the other hand is a hazy area.

The first problem is actually instantiating the controller itself, e.g.

class BlogsControllerTestCase extends UnitTestCase
{
	function setUp()
	{
		$this->object = new Blogs;
	}
.......
......

This throws an error of the form:
Fatal error: Class 'Blogs' not found in /path/to/cake/tests/app/cases/controllers/blogs_controller.test.php on line 16

The same error happens for $this->object = new BlogsController;

After bringing this up on the IRC channel, Gwoo was kind enough to suggest using loadController. The result:

loadController('Blogs');

class BlogsControllerTestCase extends UnitTestCase
{
	function setUp()
	{
		$this->object = new BlogsController;
	}
.......
......


seems to load the controller. Cool!

However, instantiating the Controller in this way doesn't seem to load the related Model, as once an action of the controller is called, (e.g. $this->object->index();),  we get complaints about any calls to model functions within that action. 
e.g.

Fatal error: Call to a member function validates() on a non-object in ...........

Can anyone throw some light on the subject here. I've been trying to get a handle on controller testing for months at this stage and as a result, my controllers are untested.

All comments / suggestions will be very much appreciated.

Cheers,

Sonic.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [email protected]
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