CakePHP fixtures exporter for phpMyAdmin

One of the best features in CakePHP is it's testsuite. I now use it all the time, it takes some time to some time to setup initially, but once it's working the payoff is massive.

One of the most time consuming is setting up test fixtures, these define the table schema and data used for testing. Now you don't have to use this feature, without fixtures, tests simple use the real tables, however I think that is a terrible idea.

To simplify creating fixtures I have created an export script for phpMyAdmin. It uses the export feature of phpMyAdmin and supports whole table export or selected rows.

Download

To install extract the cakefixture.php file and place in the libraries/export directory of phpMyAdmin. A 'CakePHP Fixture' option will now be available for export

Model Class names

Unfortunately the exporter cannot access the CakePHP inflector so tries a very primitive guess at what the class name should be from the table name, it works in the most common cases, however you need to check the class names are correct.

on 4th February 2013

2 Comments


B. Karstaedt
Oct 28, 2013
To export fixtures from existing table data just use the baking tool shipped with CakePHP (see http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html) via 'cake bake fixture'. During the process you will be asked if you want to build the fixture from an existing table - say yes and the fixture will be generated for you.


Colin
Dec 05, 2013
Ah yes, I forgot to mention the bake script.
However with the bake script it can difficult to select specific rows if they don't fit in a specific where condition.
I find using phpMyAdmin to select specific rows is much easier, especially when I want to add new data rows from existing data to a fixture.
I usually do use the bake script to create the initial fixture and then use phpMyAdmin to cherry pick specific rows I need for testing.

Add new comment