/[web]/fidd/lib/fabpot-yaml/test/sfYamlParserTest.php
ViewVC logotype

Contents of /fidd/lib/fabpot-yaml/test/sfYamlParserTest.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1081 - (show annotations) (download)
Mon May 14 09:16:32 2012 UTC (11 years, 11 months ago) by rda
File size: 1843 byte(s)
add library and var dir
1 <?php
2
3 /*
4 * This file is part of the symfony package.
5 * (c) Fabien Potencier <fabien.potencier@symfony-project.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
11 require_once(dirname(__FILE__).'/lime/lime.php');
12 require_once(dirname(__FILE__).'/../lib/sfYaml.php');
13 require_once(dirname(__FILE__).'/../lib/sfYamlParser.php');
14
15 sfYaml::setSpecVersion('1.1');
16
17 $t = new lime_test(153);
18
19 $parser = new sfYamlParser();
20
21 $path = dirname(__FILE__).'/fixtures';
22 $files = $parser->parse(file_get_contents($path.'/index.yml'));
23 foreach ($files as $file)
24 {
25 $t->diag($file);
26
27 $yamls = file_get_contents($path.'/'.$file.'.yml');
28
29 // split YAMLs documents
30 foreach (preg_split('/^---( %YAML\:1\.0)?/m', $yamls) as $yaml)
31 {
32 if (!$yaml)
33 {
34 continue;
35 }
36
37 $test = $parser->parse($yaml);
38 if (isset($test['todo']) && $test['todo'])
39 {
40 $t->todo($test['test']);
41 }
42 else
43 {
44 $expected = var_export(eval('return '.trim($test['php']).';'), true);
45
46 $t->is(var_export($parser->parse($test['yaml']), true), $expected, $test['test']);
47 }
48 }
49 }
50
51 // test tabs in YAML
52 $yamls = array(
53 "foo:\n bar",
54 "foo:\n bar",
55 "foo:\n bar",
56 "foo:\n bar",
57 );
58
59 foreach ($yamls as $yaml)
60 {
61 try
62 {
63 $content = $parser->parse($yaml);
64 $t->fail('YAML files must not contain tabs');
65 }
66 catch (InvalidArgumentException $e)
67 {
68 $t->pass('YAML files must not contain tabs');
69 }
70 }
71
72 $yaml = <<<EOF
73 --- %YAML:1.0
74 foo
75 ...
76 EOF;
77
78 $t->is('foo', $parser->parse($yaml));
79
80 // objects
81 $t->diag('Objects support');
82 class A
83 {
84 public $a = 'foo';
85 }
86 $a = array('foo' => new A(), 'bar' => 1);
87 $t->is($parser->parse(<<<EOF
88 foo: !!php/object:O:1:"A":1:{s:1:"a";s:3:"foo";}
89 bar: 1
90 EOF
91 ), $a, '->parse() is able to dump objects');

  ViewVC Help
Powered by ViewVC 1.1.30