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:
-
table2_id: 1
column5: fhah
column6: 456
column7: 46.5
column8: "fsdb, ghfdas"
-
table2_id: 3
column5: ajsdlkfguitah
column6: 654
column7: blah
column8: |-
thesethasdl
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.
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…
It should be externalled at PHPUnit/Util/YAML?
Check the bottom of this page and you’ll see the external:
http://www.phpunit.de/browser/phpunit/trunk/PHPUnit/Util
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.
Thanks!
Can’t anybody update documentation?
Database extension has no info about this at all.
http://www.phpunit.de/manual/3.4/en/database.html#database.operations
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
.
hello~ thanks for your efforts
what’s going on here?
i cannot find the yaml classes anywhere
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);
}
[/lang]