4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Yaml\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Yaml\Yaml;
17 class YamlTest extends TestCase
19 public function testParseAndDump()
21 $data = array('lorem' => 'ipsum', 'dolor' => 'sit');
22 $yml = Yaml::dump($data);
23 $parsed = Yaml::parse($yml);
24 $this->assertEquals($data, $parsed);
30 public function testLegacyParseFromFile()
32 $filename = __DIR__.'/Fixtures/index.yml';
33 $contents = file_get_contents($filename);
34 $parsedByFilename = Yaml::parse($filename);
35 $parsedByContents = Yaml::parse($contents);
36 $this->assertEquals($parsedByFilename, $parsedByContents);
40 * @expectedException \InvalidArgumentException
41 * @expectedExceptionMessage The indentation must be greater than zero
43 public function testZeroIndentationThrowsException()
45 Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, 0);
49 * @expectedException \InvalidArgumentException
50 * @expectedExceptionMessage The indentation must be greater than zero
52 public function testNegativeIndentationThrowsException()
54 Yaml::dump(array('lorem' => 'ipsum', 'dolor' => 'sit'), 2, -4);