YAML Now Supported by PHPUnit Database Extension

I have now just committed YAML data sets to the Database Extension for PHPUnit. So now all those that love the simplicity and straightforwardness of YAML can use it with your data sets. I have also created a persistor for YAML datasets so you can easily convert existing data sets or database data into YAML representations.

This is really the first I have dealt with YAML and it is definitely a viable alternative for data sets. Here is what they will look like.

    table1_id: 1
    columnName1: "tgfahgasdf"
    columnName2: 200
    columnName3: 34.64
    columnName4: yghkf;a  hahfg8ja h;
    table2_id: 1
    column5: fhah
    column6: 456
    column7: 46.5
    column8: "fsdb, ghfdas"
    table2_id: 3
    column5: ajsdlkfguitah
    column6: 654
    column7: blah
    column8: |-
      asdflkjsadf asdfsadfhl "adsf, halsdf" sadfhlasdf

The biggest issue I had was figuring out how YAML dealt with trailing line breaks. It appears that ‘|-’ did the trick. It will strip the final line break. Another thing to take note is that indention is important. It doesn’t HAVE to be spaces (it can be tabs) it just needs to be consistent. The last thing is that strings do not need to be quoted, but if they are you can use escape characters (like \n.)

This was committed to the trunk of PHPUnit and I anticipate Sebastian will be merging it back into 3.4 shortly.

This entry was posted in PHP Testing. Bookmark the permalink.

8 Responses to YAML Now Supported by PHPUnit Database Extension

  1. I browsed phpunit’s trac a bit and looks like it is not commited properly. You reference PHPUnit/Util/YAML/sfYaml.class.php file, but it is not in the tree…

  2. Mike Lively says:

    It should be externalled at PHPUnit/Util/YAML?

  3. Mike Lively says:

    Check the bottom of this page and you’ll see the external:


  4. Jack says:

    Can you give an example of how to use it? I’ve looked around in the API documentation but I didn’t see a PHPUnit_Extensions_Database_DataSet_YamlDataSet or anything similar.


  5. MK says:

    Can’t anybody update documentation?
    Database extension has no info about this at all.

  6. Mike Lively says:

    Largely a lack of time on my part. There will be a fairly thorough description of this functionality in a soon to be released book. I am also attempting to put some more time in on my personal projects which would include some long awaited documentation and bug fixes. I have to feed the family first ;).

  7. kiddyfurby says:

    hello~ thanks for your efforts
    what’s going on here?
    i cannot find the yaml classes anywhere

  8. kiddyfurby says:

    found it, with 3.4.12 (current stable), there’s actually a yaml data set class
    thanks for the great work, yaml is great for fixture

    [geshi lang=php]
    require_once ‘PHPUnit/Extensions/Database/DataSet/YamlDataSet.php’;
    protected function getDataSet() {
    return new PHPUnit_Extensions_Database_DataSet_YamlDataSet($path_to_yaml);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>