Posts Tagged ‘testing’

CakePHP: Testing static database tables

Tuesday, November 30th, 2010

Took a while to work out how to do this, hope it helps someone. If you are unit testing models in CakePHP against large database tables that don’t ever change (in my case millions of rows of location data), you don’t really want to bother copying everything to the test database, or worse have the data re-imported before each individual test.

Instead you can set up your fixture like this:

class MyBigStaticTableFixture extends CakeTestFixture {
    var $name = 'MyBigStaticTable';
    var $table = 'my_big_static_tables';
    var $import = array('model' => 'MyBigStaticTable', 'records' => false);
}

// and your model test case as follows:

class MyBigStaticTableTestCase {
    ...
    function startTest() {
        ClassRegistry::config(array('ds' => 'default'));
        $this->MyBigStaticTable => ClassRegistry::init(array(
            'class' => 'MyBigStaticTable', 'ds' => 'default'));
    }
    ...
}

Not currently sure how this will affect related models. This is with CakePHP version 1.2 but I think should also work with 1.3.

Happy testing.

Android test post

Sunday, July 11th, 2010

Hey, I don’t have anything particular to say but I can say it from my Android phone, which is pretty groovy.

You know, it’s not about the message any more, it’s all about the medium.

I might limit paragraphs to one sentence, in honour of the Sun’s editorial style.

Amanda, 19, from Hull thinks this is a good thing for society.