Hi Matt, Thanks very, very much for sharing this. I now have a working model unit test :)
As the next step it would be nice to see a documented solution in the Cookbook. I know there are many ways to skin a cat, but I'm still searching for some concensus from CakePHP unit testers as to the optimum or preferred construction of a simple model unit test that would serve as a good cookbook example to a beginner (like me). What I hadn't mentioned is that I have previously got the current cookbook example running fine. However this uses the user_test_fixture.php filenaming convention and the inclusion in the test case of: class UserTest extends User { var $name = 'UserTest'; var $useDbConfig = 'test_suite'; } It also relies on the DB defined as $test in database.php having an empty table called 'users' already created. Your solution, on the other hand, uses $this->User = ClassRegistry::init('User'); but requires that the 'test' DB is empty - no tables. So these two solutions seem incompatible. I've also looked at Debuggable's model unit test example at: http://debuggable.com/posts/testing-models-in-cakephp---now-let%27s-get-rid-of-the-unnecessary-modeltest-classes-!:4890ed55-be28-4d4a-ba4c-7fd64834cda3 Their solution includes a 'fixturize' script which generates a fixture file. But the fixture it generates is not compatible with your unit test. Plus I've failed miserably to get the Debuggable example running without errors. So, moving forward today I'm going to be writing some tests using your template. Thanks, Andy On Nov 26, 3:40 pm, Matt Curry <[EMAIL PROTECTED]> wrote: > Here you go:http://github.com/mcurry/cakephp/tree/master/test_sample > > This is the template for tests that I uses. It took me like 2 days to > get it working, even though there are only like two differences from > the standard baked tests. > > One note: You have to include all the fixtures for associated models, > which generally ends up being all the models. > > On Nov 25, 5:41 pm, pragna <[EMAIL PROTECTED]> wrote: > > > 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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---