Tuesday, November 25, 2008

Re: CakePHP Unit Test Model Woes :(

Hi Matt,
Thanks but I'm still not quite there. I have tried variations on most
of these calls already.
My test database is not empty - it has a users table but there are no
records in the table. I get Error: Database table users for model
User was not found if I have no users table in the 'test' DB and it
uses this table with the var $import = array('table' => 'name',
'records' => false); line you mentioned.
I have been through your suggestions 1 by 1 but still don't have a
working test. You don't have a very simple example of a working model
test you could share by any chance?
Thanks,
Andy

On Nov 25, 10:04 pm, MattC <m...@mcurry.net> wrote:
> This may or may not fix your problem but:
> 1) You test db should be empty.  The framework will automatically
> create/drop the tables for each test.
> 2) You don't need to call "loadFixtures" at the start of each test.
> 3) I don't think you need to App::import your model if you use
> ClassRegistry::init.  Not 100% on that, and it shouldn't hurt even if
> you do.
> 4) In my fixtures I have the line:
> var $import = array('table' => 'name', 'records' => false);
> I had to use the actually table name to get everything working with
> ClassRegistry setting the right database.  It didn't work if I just
> specified the model.
>
> Hope that helps.
> -Matthttp://www.pseudocoder.com
>
> On Nov 25, 4:29 pm, pragna <a...@andyjordan.com> wrote:
>
> > I've been struggling for a couple of days now to build a very simple
> > 'model' unit test.
>
> > CakePHPs "Convention over Configuration" should help me out here and
> > so should the Cookbook.
>
> > With Unit Tests though, it's quite hard to uncover the what the
> > conventions are. The filename conventions described in the Cookbook
> > (1.2) differ from, for example, the fixture files created using Bake.
> > Also the guys at Debuggable have re-factored and simplified the
> > building of model tests as well as sharing a fixturize script that
> > automates the building of fixtures.
>
> > All great stuff!
> > If only I could get the simplest test up and running :(
>
> > My failing code is here:http://oneyeareatingcake.blogspot.com/2008/11/cakephp-unit-test-model...
>
> > It is the most basic of Unit Tests on a simple findAll function in the
> > most basic of models. The reason this is not working has to be that
> > I'm breaking the convention somewhere. Maybe in file naming or in the
> > way I'm including the fixture?
>
> > I'd be very grateful if someone could get me out of this mess by
> > pointing out what I've got wrong.
> > Thanks,
> > Andy

--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: