views:

340

answers:

2

Is it possible to have a fixture change between test methods? If so, how can I do this?

My syntax for this problem :

In the cakephp framework i am building tests for a behavior that is configured by adding fields to the table. This is intended to work in the same way that adding the "created" and "modified" fields will auto-populate these fields on save.

To test this I could create dozens of fixtures/model combos to test the different setups, but it would be a hundred times better, faster and easier to just have the fixture change "shape" between test methods.

If you are not familiar with the CakePHP framework, you can maybe still help me as it uses SimpleTest

Edit: rephrased question to be more general

A: 

I'm not familiar specifically with CakePHP, but this kind of thing seems to happen anywhere with fixtures.

There is no built in way in rails at least for this to happen, and I imagine not in cakePHP or anywhere else either because the whole idea of a fixture, is that it is fixed

There are 2 'decent' workarounds I'm aware of

  • Write a changefixture method, and just before you do your asserts/etc, run it with the parameters of what to change. It should go and update the database or whatever needs to be done.

  • Don't use fixtures at all, and use some kind of object factory or object generator to create your objects each time

Orion Edwards
A: 

This is not an answer to my quetion, but a solution to my issue example.

Instead of using multiple fixtures or changing the fixtures, I edit the Model::_schema arrays by removing the fields that I wanted to test without. This has the effect that the model acts as if the fields was not there, but I am unsure if this is a 100% test. I do not think it is for all cases, but it works for my example.

Alexander Morland