Unit testing CakePHP application that uses stored procedures

cakephp, mysql, stored-procedures, unit-testing

Solution

Overload the Fixture’s create() method. Don’t forget to call parent’s create() and remove the final delimiter after the closing END in the create procedure statement.

e.g.:

public function create($db){
    parent::create($db);
    // create stored procedures ...
    $db->execute("CREATE PROCEDURE … <insert SQL here> … END", array('log' => false));
}

The create() method can execute any statements you need after the fixture table is created.

I hope it will work

Problem

Does anyone know of the correct way to develop unit tests for a CakePHP 2.3.1 application that utilises MySQL stored procedures? I've looked on the cake site but the documentation on testing isn't huge. I've checked out SO and Google as well - can't seem to find mention of the problem/situation. The unit testing is using fixtures, not a real database for the data. Any help/pointers are really appreciated! J

Original source