CakePHP testing Errors: Database table not found - Enum type fields ignored

We got the chance to use CakePHP Test Suite v 1.2.0.0 for one of our customers who requested creating test cases for all models and controllers in the project. I got a feedback from one of our developers with the following two problems while generating and running the test cases for models:

1- CakePHP complains about missing database tables for some models.
2- Enum fields data types are not supported anywhere by the test suite.

Chances are if you are reading this, then you already know the basics and read the testing section in CakePHP. So, in short, for each test case for models, CakePHP call the necessary function to create a table, fill it with data and then drop it. As of writing this blog, CakePHP does not generate Enum fields nor does it put the necessary data for it in the fixture while baking a model. I prefer to follow Cake convention and rely on standardized baked code as much as possible. The best two possible scenarios I found to set the fixtures and database tables are:

1- Rely on CakePHP table generation, in this case your test cases will not cover any Enum fields generation and testing, so take that into consideration for any custom test case. Also, for all models associated with the model you are testing, there should exist a fixture for the associated model and add the fixture to the list of fixtures for your test cases. You may end up with a really big array, I found no other solution but to create all fixtures for them and include them all in the test case.

  1. <?php
  2. 	var $fixtures = array('app.basket', 'app.category', 'app.address', 'app.user', 'app.photo',
  3. 		'app.payment_credit_card', 'app.payment_credit_card_type', 'app.payment_stored_payment',
  4. 		'app.payment_gift_certificate_redeem', 'app.payment_member_balance', 'app.item_listing', 'app.item',
  5. 		'app.shop', 'app.shipping_option', 'app.tag', 'app.word');
  6. ?>

2- Use your own test data and database. In this case watch out for Enum fields in your database and the data in the fixture and the expected returned value from find operations. Moreover, you will have to override the create and drop functions in you fixtures to prevent Cake from creating and doping tables on its own. It would be a lot better if there was a generic CakeTestFixture that we can change in it and in turn change in all our fixtures like AppModel. Unfortunately, generated fixtures directly use CakeTestFixture. So you can either create your own costume TestFixture , or override the following functions in each fixture you create.

  1. <?php
  2. 	function create(&$db) {
  3. 		return true;
  4. 	}
  5. 	function drop(&$db) {
  6. 		return true;
  7. 	}
  8. ?>

I am not a big fan of the second option due to the large amount of non-standard code. Also, the first option ignores Enum fields completely. So till the CakePHP bakers add the ingredients to support Enum fields, I guess we have to pick one.