====Everything I Know About Getting Model Tests to Work Half-Way Rationally in CakePhp==== ===My Sources=== http://github.com/mcurry/cakephp/tree/master/test_sample/tests http://debuggable.com/posts/testing-models-in-cakephp---now-let's-get-rid-of-the-unnecessary-modeltest-classes-!:4890ed55-be28-4d4a-ba4c-7fd64834cda3#comment-492aedab-164c-421c-a1a8-4d854834cda3 ===Some Caveats=== ~- It's possible that this will not work depending on which release of CakePhp we have installed. Testing seems to be a part of the codebase that is still in a bit of flux. ~- You'll want to set up a second empty database. At home I have two databases set up for model testing: db1 (database with all tables) db1-fixture (empty database -- CakePhp creates tables here for test and truncates at end) ~- You need to have fixtures set up for the model you're testing and all associated models. Fortunately, the fixtures are very simple. ~- Add a 'test_suite' option to config/database.php and set the db to your new empty database (e.g. db1-fixture). ~- If you run into db table not found errors, make sure your fixture db is completely empty. If it has tables in it at the start of test, I would get this error for some reason. Just truncate the db. ~- Start with a simple example from your project based on the sample code and build from there. ===Simple Examples=== %%(php) 'models', 'import' => false); var $useDbConfig = 'test_suite'; var $records = array( array( 'id' => 1, 'etc' => 0, ) ); } ?> %% %%(php) Model = ClassRegistry::init('Model'); } function testInstance() { $this->assertTrue(is_a($this->Model, 'Model')); } } ?> %%