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