Migrate phpunit fixtures in the case of new field to table

If there is a requirement to add new field to existing DB table, we can achieve the same using migration script. In these case, how to migrate the same to PHPunit fixtures.

Is there a way to do it?


Copy your custom records before re-baking the fixture class and drop your records back in and add your new field to each.

Thanks for your reply @deanoj

But then, adding field to each record will be hectic for large amount of records.

Yes correct. I’ve been through this pain myself and now I make sure my tests only have a handful of fixture records.

If you do require a large amount of fixture records for your tests then you should look into generating the records dynamically within the fixture, then all you have to change is your generation code.

Worth a mention, I have also used a CSV flat file to hold fixture records - I write some code to read the file and generate the records dynamically. You may find this an easier solution as you can then use Excel or similar to edit the CSV file.

Thanks @deanoj

Will work onto it. Yes loading fixture records dynamically would solve the issue