While implementing fixture support in the testsuite the question arised which format should be used for the fixtures? The first answer was: YAML, of course. It is used in Ruby on Rails, so it cannot be bad ;-) Hm. Let’s have a look at a simple YAML example:

// urls.yml
cakephp:
  id: 1
  name: CakePHP website
  url: http://www.cakephp.org

manual:
  id: 2
  name: CakePHP manual
  url: http://manual.cakephp.org

It looks nice. But there is one “problem”. It violates the DRY (Don’t repeat yourself) principle: the column names are repeated in each record.

So I decided to use a different approach: plain PHP. It is simple: each fixture is a class, and each record is a function. The YAML example from above rewritten as a class looks like:

class Urls
{
    function cakephp()
    {
        return array(1, 'CakePHP website', 'http://www.cakephp.org');
    }

    function manual()
    {
        return array(2, 'CakePHP manual', 'http://manual.cakephp.org');
    }
}

Simple, isn’t it?