I am writing a PHPUnit test for my Yii application. I read here:
Tip: Having too many fixture files could increase the test time dramatically. For this reason, you should only provide fixture files for those tables whose content may change during the test. Tables that serve as look-ups do not change and thus do not need fixture files.
I indeed have a large fixture (180 records, which takes >20 seconds to load), which is only used as a look-up. However, I do need to transform it easily from an associative array into a Model object, like you can usually do with the fixture syntax below. The tip suggests that there is also a way to create a Model object without the use of a fixture, but does not mention how this is done. Can anyone help out?
Creation of Model object with a fixture:
// tests/fixtures/Order.php
return array(
'row_id' => array(
'id' => 1,
'name' => 'hello',
)
)
// tests/unit/AbcTest.php
public $fixtures = array(
'orders' => 'Order',
)
public test_abc()
{
$order = $this->orders('row_id');
....
}
Another option:
when you create db migration you should apply it on production db and on test db moreover you should populate test tables with test data.
Benefits of this approach:
For example:
And in test you don't have to think about fixtures.