klenwell information services : SpecialCakePhpModelTesting

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

db1 (database with all tables)
db1-fixture (empty database -- CakePhp creates tables here for test and truncates at end)


Simple Examples

<?php
 
    class ModelFixture extends CakeTestFixture
    {
        var $name = 'Model';
        var $import = array('table' => 'models', 'import' => false);
        var $useDbConfig = 'test_suite';
       
        var $records = array(
            array(
                'id' => 1,
                'etc' => 0,
            )
        );
    }
?>


<?php
/*
    Based on mcurry's template at
    http://github.com/mcurry/cakephp/tree/master/test_sample/tests
*/

 
class ExtagProofCase extends CakeTestCase {

    var $Model = null;
    var $fixtures = array(
            'app.model',
            'app.model1',
            'app.model2',
            );
 
    function start()
    {
        parent::start();
        $this->Model = ClassRegistry::init('Model');
    }
   
    function testInstance() {
        $this->assertTrue(is_a($this->Model, 'Model'));
    }
}
?>