Yii Framework Easy Test Fixture Creation

We’ve said it before, and we’ll say it again – we are huge fans of the Yii Framework.  This PHP framework is easy to understand, and even better, easy to create test cases.  One of the most time consuming portions of writing the test suite, however, was getting your test data into Yii’s ‘fixture’ files.  These fixture files correspond to data that would be in your database tables, but the files stay constant so you always have a known start state.  That way, you can test your application easily at any time, ensuring that your recent build hasn’t broken any legacy functions.

Due to the fixture files, we had resorted to running a custom script that took data out of our production database and exported it to a fixture file.  However, with a recent new installation of phpMyAdmin, we came across the PHP Array plugin.  Using this plugin, you can easily export your table data into PHP array format – the same format that is needed for your Yii fixture files.

We hope this saves someone some time and hassle down the road!

Read More

Yii Framework Test Script Submitting to Production

Edit: It looks like our RewriteRule directives in Apache may have been the culprit. We rarely use a .htaccess file and instead use configuration files to speed up Apache. Since we didn’t change index.php to index-test.php in the configuration, it was redirecting to the index.php!

In the Yii Framework, you can always call index-test.php to use your test settings & database connection. This is handy in a variety of ways. However, we recently found that some actions (redirects) that occurred after a page submit were redirecting us to the index.php – the production site. Luckily, we were still on our local machine, so we had no test cases misdirecting from test to production. To fix this, we set the URL Manager’s showScriptName to true in our test configuration. After we did this, everything worked as expected.

Snippet from our test configuration file:

// uncomment the following to enable URLs in path-format
   'showScriptName' => true,

Read More