YamlTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Yaml\Tests;
  11. use Symfony\Component\Yaml\Yaml;
  12. class YamlTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testParseAndDump()
  15. {
  16. $data = array('lorem' => 'ipsum', 'dolor' => 'sit');
  17. $yml = Yaml::dump($data);
  18. $parsed = Yaml::parse($yml);
  19. $this->assertEquals($data, $parsed);
  20. }
  21. /**
  22. * @group legacy
  23. */
  24. public function testLegacyParseFromFile()
  25. {
  26. $filename = __DIR__.'/Fixtures/index.yml';
  27. $contents = file_get_contents($filename);
  28. $parsedByFilename = Yaml::parse($filename);
  29. $parsedByContents = Yaml::parse($contents);
  30. $this->assertEquals($parsedByFilename, $parsedByContents);
  31. }
  32. /**
  33. * @expectedException \InvalidArgumentException
  34. * @expectedExceptionMessage The indentation must be greater than zero
  35. */
  36. public function testZeroIndentationThrowsException()
  37. {
  38. Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, 0);
  39. }
  40. /**
  41. * @expectedException \InvalidArgumentException
  42. * @expectedExceptionMessage The indentation must be greater than zero
  43. */
  44. public function testNegativeIndentationThrowsException()
  45. {
  46. Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, -4);
  47. }
  48. }