/framework/vendor/spyc/lib/tests/DumpTest.php

http://zoop.googlecode.com/ · PHP · 58 lines · 46 code · 12 blank · 0 comment · 0 complexity · 831a122c8d7c49f036ae6728aef83c2d MD5 · raw file

  1. <?php
  2. require_once ("../spyc.php");
  3. class DumpTest extends PHPUnit_Framework_TestCase {
  4. private $files_to_test = array();
  5. public function setUp() {
  6. $this->files_to_test = array ('../spyc.yaml', 'failing1.yaml', 'indent_1.yaml', 'quotes.yaml');
  7. }
  8. public function testDump() {
  9. foreach ($this->files_to_test as $file) {
  10. $yaml = spyc_load(file_get_contents($file));
  11. $dump = Spyc::YAMLDump ($yaml);
  12. $yaml_after_dump = Spyc::YAMLLoad ($dump);
  13. $this->assertEquals ($yaml, $yaml_after_dump);
  14. }
  15. }
  16. public function testDumpWithQuotes() {
  17. $Spyc = new Spyc();
  18. $Spyc->setting_dump_force_quotes = true;
  19. foreach ($this->files_to_test as $file) {
  20. $yaml = $Spyc->load(file_get_contents($file));
  21. $dump = $Spyc->dump ($yaml);
  22. $yaml_after_dump = Spyc::YAMLLoad ($dump);
  23. $this->assertEquals ($yaml, $yaml_after_dump);
  24. }
  25. }
  26. public function testDumpArrays() {
  27. $dump = Spyc::YAMLDump(array ('item1', 'item2', 'item3'));
  28. $awaiting = "---\n- item1\n- item2\n- item3\n";
  29. $this->assertEquals ($awaiting, $dump);
  30. }
  31. public function testDumpNumerics() {
  32. $dump = Spyc::YAMLDump(array ('404', '405', '500'));
  33. $awaiting = "---\n- 404\n- 405\n- 500\n";
  34. $this->assertEquals ($awaiting, $dump);
  35. }
  36. public function testDumpAsterisks() {
  37. $dump = Spyc::YAMLDump(array ('*'));
  38. $awaiting = "---\n- '*'\n";
  39. $this->assertEquals ($awaiting, $dump);
  40. }
  41. public function testEmpty() {
  42. $dump = Spyc::YAMLDump(array("foo" => array()));
  43. $awaiting = "---\nfoo: [ ]\n";
  44. $this->assertEquals ($awaiting, $dump);
  45. }
  46. }