ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ParserTest.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
13
16
18{
19 protected $parser;
20
21 protected function setUp()
22 {
23 $this->parser = new Parser();
24 }
25
26 protected function tearDown()
27 {
28 $this->parser = null;
29 }
30
34 public function testSpecifications($file, $expected, $yaml, $comment)
35 {
36 $this->assertEquals($expected, var_export($this->parser->parse($yaml), true), $comment);
37 }
38
39 public function getDataFormSpecifications()
40 {
41 $parser = new Parser();
42 $path = __DIR__.'/Fixtures';
43
44 $tests = array();
45 $files = $parser->parse(file_get_contents($path.'/index.yml'));
46 foreach ($files as $file) {
47 $yamls = file_get_contents($path.'/'.$file.'.yml');
48
49 // split YAMLs documents
50 foreach (preg_split('/^---( %YAML\:1\.0)?/m', $yamls) as $yaml) {
51 if (!$yaml) {
52 continue;
53 }
54
55 $test = $parser->parse($yaml);
56 if (isset($test['todo']) && $test['todo']) {
57 // TODO
58 } else {
59 eval('$expected = '.trim($test['php']).';');
60
61 $tests[] = array($file, var_export($expected, true), $test['yaml'], $test['test']);
62 }
63 }
64 }
65
66 return $tests;
67 }
68
69 public function testTabsInYaml()
70 {
71 // test tabs in YAML
72 $yamls = array(
73 "foo:\n bar",
74 "foo:\n bar",
75 "foo:\n bar",
76 "foo:\n bar",
77 );
78
79 foreach ($yamls as $yaml) {
80 try {
81 $content = $this->parser->parse($yaml);
82
83 $this->fail('YAML files must not contain tabs');
84 } catch (\Exception $e) {
85 $this->assertInstanceOf('\Exception', $e, 'YAML files must not contain tabs');
86 $this->assertEquals('A YAML file cannot contain tabs as indentation at line 2 (near "'.strpbrk($yaml, "\t").'").', $e->getMessage(), 'YAML files must not contain tabs');
87 }
88 }
89 }
90
92 {
93 $yaml = <<<'EOF'
94--- %YAML:1.0
95foo
96...
97EOF;
98
99 $this->assertEquals('foo', $this->parser->parse($yaml));
100 }
101
102 public function getBlockChompingTests()
103 {
104 $tests = array();
105
106 $yaml = <<<'EOF'
107foo: |-
108 one
109 two
110bar: |-
111 one
112 two
113
114EOF;
115 $expected = array(
116 'foo' => "one\ntwo",
117 'bar' => "one\ntwo",
118 );
119 $tests['Literal block chomping strip with single trailing newline'] = array($expected, $yaml);
120
121 $yaml = <<<'EOF'
122foo: |-
123 one
124 two
125
126bar: |-
127 one
128 two
129
130
131EOF;
132 $expected = array(
133 'foo' => "one\ntwo",
134 'bar' => "one\ntwo",
135 );
136 $tests['Literal block chomping strip with multiple trailing newlines'] = array($expected, $yaml);
137
138 $yaml = <<<'EOF'
139{}
140
141
142EOF;
143 $expected = array();
144 $tests['Literal block chomping strip with multiple trailing newlines after a 1-liner'] = array($expected, $yaml);
145
146 $yaml = <<<'EOF'
147foo: |-
148 one
149 two
150bar: |-
151 one
152 two
153EOF;
154 $expected = array(
155 'foo' => "one\ntwo",
156 'bar' => "one\ntwo",
157 );
158 $tests['Literal block chomping strip without trailing newline'] = array($expected, $yaml);
159
160 $yaml = <<<'EOF'
161foo: |
162 one
163 two
164bar: |
165 one
166 two
167
168EOF;
169 $expected = array(
170 'foo' => "one\ntwo\n",
171 'bar' => "one\ntwo\n",
172 );
173 $tests['Literal block chomping clip with single trailing newline'] = array($expected, $yaml);
174
175 $yaml = <<<'EOF'
176foo: |
177 one
178 two
179
180bar: |
181 one
182 two
183
184
185EOF;
186 $expected = array(
187 'foo' => "one\ntwo\n",
188 'bar' => "one\ntwo\n",
189 );
190 $tests['Literal block chomping clip with multiple trailing newlines'] = array($expected, $yaml);
191
192 $yaml = <<<'EOF'
193foo: |
194 one
195 two
196bar: |
197 one
198 two
199EOF;
200 $expected = array(
201 'foo' => "one\ntwo\n",
202 'bar' => "one\ntwo",
203 );
204 $tests['Literal block chomping clip without trailing newline'] = array($expected, $yaml);
205
206 $yaml = <<<'EOF'
207foo: |+
208 one
209 two
210bar: |+
211 one
212 two
213
214EOF;
215 $expected = array(
216 'foo' => "one\ntwo\n",
217 'bar' => "one\ntwo\n",
218 );
219 $tests['Literal block chomping keep with single trailing newline'] = array($expected, $yaml);
220
221 $yaml = <<<'EOF'
222foo: |+
223 one
224 two
225
226bar: |+
227 one
228 two
229
230
231EOF;
232 $expected = array(
233 'foo' => "one\ntwo\n\n",
234 'bar' => "one\ntwo\n\n",
235 );
236 $tests['Literal block chomping keep with multiple trailing newlines'] = array($expected, $yaml);
237
238 $yaml = <<<'EOF'
239foo: |+
240 one
241 two
242bar: |+
243 one
244 two
245EOF;
246 $expected = array(
247 'foo' => "one\ntwo\n",
248 'bar' => "one\ntwo",
249 );
250 $tests['Literal block chomping keep without trailing newline'] = array($expected, $yaml);
251
252 $yaml = <<<'EOF'
253foo: >-
254 one
255 two
256bar: >-
257 one
258 two
259
260EOF;
261 $expected = array(
262 'foo' => 'one two',
263 'bar' => 'one two',
264 );
265 $tests['Folded block chomping strip with single trailing newline'] = array($expected, $yaml);
266
267 $yaml = <<<'EOF'
268foo: >-
269 one
270 two
271
272bar: >-
273 one
274 two
275
276
277EOF;
278 $expected = array(
279 'foo' => 'one two',
280 'bar' => 'one two',
281 );
282 $tests['Folded block chomping strip with multiple trailing newlines'] = array($expected, $yaml);
283
284 $yaml = <<<'EOF'
285foo: >-
286 one
287 two
288bar: >-
289 one
290 two
291EOF;
292 $expected = array(
293 'foo' => 'one two',
294 'bar' => 'one two',
295 );
296 $tests['Folded block chomping strip without trailing newline'] = array($expected, $yaml);
297
298 $yaml = <<<'EOF'
299foo: >
300 one
301 two
302bar: >
303 one
304 two
305
306EOF;
307 $expected = array(
308 'foo' => "one two\n",
309 'bar' => "one two\n",
310 );
311 $tests['Folded block chomping clip with single trailing newline'] = array($expected, $yaml);
312
313 $yaml = <<<'EOF'
314foo: >
315 one
316 two
317
318bar: >
319 one
320 two
321
322
323EOF;
324 $expected = array(
325 'foo' => "one two\n",
326 'bar' => "one two\n",
327 );
328 $tests['Folded block chomping clip with multiple trailing newlines'] = array($expected, $yaml);
329
330 $yaml = <<<'EOF'
331foo: >
332 one
333 two
334bar: >
335 one
336 two
337EOF;
338 $expected = array(
339 'foo' => "one two\n",
340 'bar' => 'one two',
341 );
342 $tests['Folded block chomping clip without trailing newline'] = array($expected, $yaml);
343
344 $yaml = <<<'EOF'
345foo: >+
346 one
347 two
348bar: >+
349 one
350 two
351
352EOF;
353 $expected = array(
354 'foo' => "one two\n",
355 'bar' => "one two\n",
356 );
357 $tests['Folded block chomping keep with single trailing newline'] = array($expected, $yaml);
358
359 $yaml = <<<'EOF'
360foo: >+
361 one
362 two
363
364bar: >+
365 one
366 two
367
368
369EOF;
370 $expected = array(
371 'foo' => "one two\n\n",
372 'bar' => "one two\n\n",
373 );
374 $tests['Folded block chomping keep with multiple trailing newlines'] = array($expected, $yaml);
375
376 $yaml = <<<'EOF'
377foo: >+
378 one
379 two
380bar: >+
381 one
382 two
383EOF;
384 $expected = array(
385 'foo' => "one two\n",
386 'bar' => 'one two',
387 );
388 $tests['Folded block chomping keep without trailing newline'] = array($expected, $yaml);
389
390 return $tests;
391 }
392
396 public function testBlockChomping($expected, $yaml)
397 {
398 $this->assertSame($expected, $this->parser->parse($yaml));
399 }
400
407 {
408 $yaml = <<<'EOF'
409foo: |-
410
411
412 bar
413
414EOF;
415 $expected = array(
416 'foo' => "\n\nbar",
417 );
418
419 $this->assertSame($expected, $this->parser->parse($yaml));
420 }
421
422 public function testObjectSupportEnabled()
423 {
424 $input = <<<EOF
425foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
426bar: 1
427EOF;
428 $this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
429 }
430
435 {
436 $input = <<<EOF
437foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
438bar: 1
439EOF;
440 $this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
441 }
442
447 {
448 $input = <<<EOF
449foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
450bar: 1
451EOF;
452 $this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
453 }
454
459 {
460 $this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
461 }
462
466 public function testObjectForMap($yaml, $expected)
467 {
468 $this->assertEquals($expected, $this->parser->parse($yaml, Yaml::PARSE_OBJECT_FOR_MAP));
469 }
470
476 {
477 $this->assertEquals($expected, $this->parser->parse($yaml, false, false, true));
478 }
479
480 public function getObjectForMapTests()
481 {
482 $tests = array();
483
484 $yaml = <<<EOF
485foo:
486 fiz: [cat]
487EOF;
488 $expected = new \stdClass();
489 $expected->foo = new \stdClass();
490 $expected->foo->fiz = array('cat');
491 $tests['mapping'] = array($yaml, $expected);
492
493 $yaml = '{ "foo": "bar", "fiz": "cat" }';
494 $expected = new \stdClass();
495 $expected->foo = 'bar';
496 $expected->fiz = 'cat';
497 $tests['inline-mapping'] = array($yaml, $expected);
498
499 $yaml = "foo: bar\nbaz: foobar";
500 $expected = new \stdClass();
501 $expected->foo = 'bar';
502 $expected->baz = 'foobar';
503 $tests['object-for-map-is-applied-after-parsing'] = array($yaml, $expected);
504
505 $yaml = <<<EOT
506array:
507 - key: one
508 - key: two
509EOT;
510 $expected = new \stdClass();
511 $expected->array = array();
512 $expected->array[0] = new \stdClass();
513 $expected->array[0]->key = 'one';
514 $expected->array[1] = new \stdClass();
515 $expected->array[1]->key = 'two';
516 $tests['nest-map-and-sequence'] = array($yaml, $expected);
517
518 $yaml = <<<YAML
519map:
520 1: one
521 2: two
522YAML;
523 $expected = new \stdClass();
524 $expected->map = new \stdClass();
525 $expected->map->{1} = 'one';
526 $expected->map->{2} = 'two';
527 $tests['numeric-keys'] = array($yaml, $expected);
528
529 $yaml = <<<YAML
530map:
531 0: one
532 1: two
533YAML;
534 $expected = new \stdClass();
535 $expected->map = new \stdClass();
536 $expected->map->{0} = 'one';
537 $expected->map->{1} = 'two';
538 $tests['zero-indexed-numeric-keys'] = array($yaml, $expected);
539
540 return $tests;
541 }
542
548 {
549 $this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
550 }
551
558 {
559 $this->parser->parse($yaml, true);
560 }
561
563 {
564 $yamlTag = <<<EOF
565foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
566bar: 1
567EOF;
568 $localTag = <<<EOF
569foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
570bar: 1
571EOF;
572
573 return array(
574 'yaml-tag' => array($yamlTag),
575 'local-tag' => array($localTag),
576 );
577 }
578
582 public function testNonUtf8Exception()
583 {
584 $yamls = array(
585 iconv('UTF-8', 'ISO-8859-1', "foo: 'äöüß'"),
586 iconv('UTF-8', 'ISO-8859-15', "euro: '€'"),
587 iconv('UTF-8', 'CP1252', "cp1252: '©ÉÇáñ'"),
588 );
589
590 foreach ($yamls as $yaml) {
591 try {
592 $this->parser->parse($yaml);
593
594 $this->fail('charsets other than UTF-8 are rejected.');
595 } catch (\Exception $e) {
596 $this->assertInstanceOf('Symfony\Component\Yaml\Exception\ParseException', $e, 'charsets other than UTF-8 are rejected.');
597 }
598 }
599 }
600
605 {
606 $yaml = <<<'EOF'
607
608collection:
609-item1
610-item2
611-item3
612
613EOF;
614
615 $this->parser->parse($yaml);
616 }
617
622 {
623 $yaml = <<<'EOF'
624
625collection:
626- key: foo
627 foo: bar
628
629EOF;
630
631 $this->parser->parse($yaml);
632 }
633
639 {
640 Yaml::parse(<<<'EOL'
641# Ranking of 1998 home runs
642---
643- Mark McGwire
644- Sammy Sosa
645- Ken Griffey
646
647# Team ranking
648---
649- Chicago Cubs
650- St Louis Cardinals
651EOL
652 );
653 }
654
658 public function testSequenceInAMapping()
659 {
660 Yaml::parse(<<<'EOF'
661yaml:
662 hash: me
663 - array stuff
664EOF
665 );
666 }
667
669 {
670 $yaml = <<<EOT
671a:
672-
673 b:
674 -
675 bar: baz
676- foo
677d: e
678EOT;
679 $expected = array(
680 'a' => array(
681 array(
682 'b' => array(
683 array(
684 'bar' => 'baz',
685 ),
686 ),
687 ),
688 'foo',
689 ),
690 'd' => 'e',
691 );
692
693 $this->assertSame($expected, $this->parser->parse($yaml));
694 }
695
697 {
698 $yaml = <<<EOT
699a:
700 b:
701 - c
702# comment
703 d: e
704EOT;
705 $expected = array(
706 'a' => array(
707 'b' => array('c'),
708 'd' => 'e',
709 ),
710 );
711
712 $this->assertSame($expected, $this->parser->parse($yaml));
713 }
714
718 public function testMappingInASequence()
719 {
720 Yaml::parse(<<<'EOF'
721yaml:
722 - array stuff
723 hash: me
724EOF
725 );
726 }
727
732 public function testScalarInSequence()
733 {
734 Yaml::parse(<<<EOF
735foo:
736 - bar
737"missing colon"
738 foo: bar
739EOF
740 );
741 }
742
754 {
755 $input = <<<EOD
756parent:
757 child: first
758 child: duplicate
759parent:
760 child: duplicate
761 child: duplicate
762EOD;
763 $expected = array(
764 'parent' => array(
765 'child' => 'first',
766 ),
767 );
768 $this->assertSame($expected, Yaml::parse($input));
769 }
770
772 {
773 $input = <<<EOD
774parent: { child: first, child: duplicate }
775parent: { child: duplicate, child: duplicate }
776EOD;
777 $expected = array(
778 'parent' => array(
779 'child' => 'first',
780 ),
781 );
782 $this->assertSame($expected, Yaml::parse($input));
783 }
784
785 public function testEmptyValue()
786 {
787 $input = <<<'EOF'
788hash:
789EOF;
790
791 $this->assertEquals(array('hash' => null), Yaml::parse($input));
792 }
793
795 {
796 $this->assertEquals(array(
797 'services' => array(
798 'app.foo_service' => array(
799 'class' => 'Foo',
800 ),
801 'app/bar_service' => array(
802 'class' => 'Bar',
803 ),
804 ),
805 ), Yaml::parse(<<<'EOF'
806# comment 1
807services:
808# comment 2
809 # comment 3
810 app.foo_service:
811 class: Foo
812# comment 4
813 # comment 5
814 app/bar_service:
815 class: Bar
816EOF
817 ));
818 }
819
821 {
822 $this->assertEquals(array('content' => <<<'EOT'
823# comment 1
824header
825
826 # comment 2
827 <body>
828 <h1>title</h1>
829 </body>
830
831footer # comment3
832EOT
833 ), Yaml::parse(<<<'EOF'
834content: |
835 # comment 1
836 header
837
838 # comment 2
839 <body>
840 <h1>title</h1>
841 </body>
842
843 footer # comment3
844EOF
845 ));
846 }
847
849 {
850 $this->assertEquals(array(array('content' => <<<'EOT'
851# comment 1
852header
853
854 # comment 2
855 <body>
856 <h1>title</h1>
857 </body>
858
859footer # comment3
860EOT
861 )), Yaml::parse(<<<'EOF'
862-
863 content: |
864 # comment 1
865 header
866
867 # comment 2
868 <body>
869 <h1>title</h1>
870 </body>
871
872 footer # comment3
873EOF
874 ));
875 }
876
878 {
879 $this->assertEquals(array(array(
880 'title' => 'some title',
881 'content' => <<<'EOT'
882# comment 1
883header
884
885 # comment 2
886 <body>
887 <h1>title</h1>
888 </body>
889
890footer # comment3
891EOT
892 )), Yaml::parse(<<<'EOF'
893-
894 title: some title
895 content: |
896 # comment 1
897 header
898
899 # comment 2
900 <body>
901 <h1>title</h1>
902 </body>
903
904 footer # comment3
905EOF
906 ));
907 }
908
910 {
911 $this->assertEquals(array(
912 'var' => 'var-value',
913 'scalar' => 'var-value',
914 'list' => array('var-value'),
915 'list_in_list' => array(array('var-value')),
916 'map_in_list' => array(array('key' => 'var-value')),
917 'embedded_mapping' => array(array('key' => 'var-value')),
918 'map' => array('key' => 'var-value'),
919 'list_in_map' => array('key' => array('var-value')),
920 'map_in_map' => array('foo' => array('bar' => 'var-value')),
921 ), Yaml::parse(<<<'EOF'
922var: &var var-value
923scalar: *var
924list: [ *var ]
925list_in_list: [[ *var ]]
926map_in_list: [ { key: *var } ]
927embedded_mapping: [ key: *var ]
928map: { key: *var }
929list_in_map: { key: [*var] }
930map_in_map: { foo: { bar: *var } }
931EOF
932 ));
933 }
934
935 public function testYamlDirective()
936 {
937 $yaml = <<<'EOF'
938%YAML 1.2
939---
940foo: 1
941bar: 2
942EOF;
943 $this->assertEquals(array('foo' => 1, 'bar' => 2), $this->parser->parse($yaml));
944 }
945
946 public function testFloatKeys()
947 {
948 $yaml = <<<'EOF'
949foo:
950 1.2: "bar"
951 1.3: "baz"
952EOF;
953
954 $expected = array(
955 'foo' => array(
956 '1.2' => 'bar',
957 '1.3' => 'baz',
958 ),
959 );
960
961 $this->assertEquals($expected, $this->parser->parse($yaml));
962 }
963
969 {
970 $yaml = <<<EOF
971foo: bar: baz
972EOF;
973
974 $this->parser->parse($yaml);
975 }
976
978 {
979 $yaml = <<<EOT
980foo:
981 bar: foobar # Note: a comment after a colon
982EOT;
983
984 $this->assertSame(array('foo' => array('bar' => 'foobar')), $this->parser->parse($yaml));
985 }
986
990 public function testCommentLikeStringsAreNotStrippedInBlockScalars($yaml, $expectedParserResult)
991 {
992 $this->assertSame($expectedParserResult, $this->parser->parse($yaml));
993 }
994
996 {
997 $tests = array();
998
999 $yaml = <<<'EOT'
1000pages:
1001 -
1002 title: some title
1003 content: |
1004 # comment 1
1005 header
1006
1007 # comment 2
1008 <body>
1009 <h1>title</h1>
1010 </body>
1011
1012 footer # comment3
1013EOT;
1014 $expected = array(
1015 'pages' => array(
1016 array(
1017 'title' => 'some title',
1018 'content' => <<<'EOT'
1019# comment 1
1020header
1021
1022 # comment 2
1023 <body>
1024 <h1>title</h1>
1025 </body>
1026
1027footer # comment3
1028EOT
1029 ,
1030 ),
1031 ),
1032 );
1033 $tests[] = array($yaml, $expected);
1034
1035 $yaml = <<<'EOT'
1036test: |
1037 foo
1038 # bar
1039 baz
1040collection:
1041 - one: |
1042 foo
1043 # bar
1044 baz
1045 - two: |
1046 foo
1047 # bar
1048 baz
1049EOT;
1050 $expected = array(
1051 'test' => <<<'EOT'
1052foo
1053# bar
1054baz
1055
1056EOT
1057 ,
1058 'collection' => array(
1059 array(
1060 'one' => <<<'EOT'
1061foo
1062# bar
1063baz
1064
1065EOT
1066 ,
1067 ),
1068 array(
1069 'two' => <<<'EOT'
1070foo
1071# bar
1072baz
1073EOT
1074 ,
1075 ),
1076 ),
1077 );
1078 $tests[] = array($yaml, $expected);
1079
1080 $yaml = <<<EOT
1081foo:
1082 bar:
1083 scalar-block: >
1084 line1
1085 line2>
1086 baz:
1087# comment
1088 foobar: ~
1089EOT;
1090 $expected = array(
1091 'foo' => array(
1092 'bar' => array(
1093 'scalar-block' => "line1 line2>\n",
1094 ),
1095 'baz' => array(
1096 'foobar' => null,
1097 ),
1098 ),
1099 );
1100 $tests[] = array($yaml, $expected);
1101
1102 $yaml = <<<'EOT'
1103a:
1104 b: hello
1105# c: |
1106# first row
1107# second row
1108 d: hello
1109EOT;
1110 $expected = array(
1111 'a' => array(
1112 'b' => 'hello',
1113 'd' => 'hello',
1114 ),
1115 );
1116 $tests[] = array($yaml, $expected);
1117
1118 return $tests;
1119 }
1120
1122 {
1123 $yaml = <<<EOT
1124test: >
1125 <h2>A heading</h2>
1126
1127 <ul>
1128 <li>a list</li>
1129 <li>may be a good example</li>
1130 </ul>
1131EOT;
1132
1133 $this->assertSame(
1134 array(
1135 'test' => <<<EOT
1136<h2>A heading</h2>
1137<ul> <li>a list</li> <li>may be a good example</li> </ul>
1138EOT
1139 ,
1140 ),
1141 $this->parser->parse($yaml)
1142 );
1143 }
1144
1146 {
1147 $yaml = <<<EOT
1148test: >
1149 <h2>A heading</h2>
1150
1151 <ul>
1152 <li>a list</li>
1153 <li>may be a good example</li>
1154 </ul>
1155EOT;
1156
1157 $this->assertSame(
1158 array(
1159 'test' => <<<EOT
1160<h2>A heading</h2>
1161<ul>
1162 <li>a list</li>
1163 <li>may be a good example</li>
1164</ul>
1165EOT
1166 ,
1167 ),
1168 $this->parser->parse($yaml)
1169 );
1170 }
1171
1176 {
1177 $this->assertSame(array('data' => 'Hello world'), $this->parser->parse($data));
1178 }
1179
1180 public function getBinaryData()
1181 {
1182 return array(
1183 'enclosed with double quotes' => array('data: !!binary "SGVsbG8gd29ybGQ="'),
1184 'enclosed with single quotes' => array("data: !!binary 'SGVsbG8gd29ybGQ='"),
1185 'containing spaces' => array('data: !!binary "SGVs bG8gd 29ybGQ="'),
1186 'in block scalar' => array(
1187 <<<EOT
1188data: !!binary |
1189 SGVsbG8gd29ybGQ=
1190EOT
1191 ),
1192 'containing spaces in block scalar' => array(
1193 <<<EOT
1194data: !!binary |
1195 SGVs bG8gd 29ybGQ=
1196EOT
1197 ),
1198 );
1199 }
1200
1204 public function testParseInvalidBinaryData($data, $expectedMessage)
1205 {
1206 $this->setExpectedExceptionRegExp('\Symfony\Component\Yaml\Exception\ParseException', $expectedMessage);
1207
1208 $this->parser->parse($data);
1209 }
1210
1211 public function getInvalidBinaryData()
1212 {
1213 return array(
1214 'length not a multiple of four' => array('data: !!binary "SGVsbG8d29ybGQ="', '/The normalized base64 encoded data \‍(data without whitespace characters\‍) length must be a multiple of four \‍(\d+ bytes given\‍)/'),
1215 'invalid characters' => array('!!binary "SGVsbG8#d29ybGQ="', '/The base64 encoded data \‍(.*\‍) contains invalid characters/'),
1216 'too many equals characters' => array('data: !!binary "SGVsbG8gd29yb==="', '/The base64 encoded data \‍(.*\‍) contains invalid characters/'),
1217 'misplaced equals character' => array('data: !!binary "SGVsbG8gd29ybG=Q"', '/The base64 encoded data \‍(.*\‍) contains invalid characters/'),
1218 'length not a multiple of four in block scalar' => array(
1219 <<<EOT
1220data: !!binary |
1221 SGVsbG8d29ybGQ=
1222EOT
1223 ,
1224 '/The normalized base64 encoded data \‍(data without whitespace characters\‍) length must be a multiple of four \‍(\d+ bytes given\‍)/',
1225 ),
1226 'invalid characters in block scalar' => array(
1227 <<<EOT
1228data: !!binary |
1229 SGVsbG8#d29ybGQ=
1230EOT
1231 ,
1232 '/The base64 encoded data \‍(.*\‍) contains invalid characters/',
1233 ),
1234 'too many equals characters in block scalar' => array(
1235 <<<EOT
1236data: !!binary |
1237 SGVsbG8gd29yb===
1238EOT
1239 ,
1240 '/The base64 encoded data \‍(.*\‍) contains invalid characters/',
1241 ),
1242 'misplaced equals character in block scalar' => array(
1243 <<<EOT
1244data: !!binary |
1245 SGVsbG8gd29ybG=Q
1246EOT
1247 ,
1248 '/The base64 encoded data \‍(.*\‍) contains invalid characters/',
1249 ),
1250 );
1251 }
1252
1254 {
1255 $yaml = <<<EOT
1256date: 2002-12-14
1257EOT;
1258 $expectedDate = new \DateTime();
1259 $expectedDate->setTimeZone(new \DateTimeZone('UTC'));
1260 $expectedDate->setDate(2002, 12, 14);
1261 $expectedDate->setTime(0, 0, 0);
1262
1263 $this->assertEquals(array('date' => $expectedDate), $this->parser->parse($yaml, Yaml::PARSE_DATETIME));
1264 }
1265
1271 public function testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
1272 {
1273 $this->setExpectedException(
1274 '\Symfony\Component\Yaml\Exception\ParseException',
1275 sprintf('Unexpected characters near "," at line %d (near "bar: "123",").', $lineNumber)
1276 );
1277
1278 $this->parser->parse($yaml);
1279 }
1280
1282 {
1283 return array(
1284 array(
1285 4,
1286 <<<YAML
1287foo:
1288 -
1289 # bar
1290 bar: "123",
1291YAML
1292 ),
1293 array(
1294 5,
1295 <<<YAML
1296foo:
1297 -
1298 # bar
1299 # bar
1300 bar: "123",
1301YAML
1302 ),
1303 array(
1304 8,
1305 <<<YAML
1306foo:
1307 -
1308 # foobar
1309 baz: 123
1310bar:
1311 -
1312 # bar
1313 bar: "123",
1314YAML
1315 ),
1316 array(
1317 10,
1318 <<<YAML
1319foo:
1320 -
1321 # foobar
1322 # foobar
1323 baz: 123
1324bar:
1325 -
1326 # bar
1327 # bar
1328 bar: "123",
1329YAML
1330 ),
1331 );
1332 }
1333}
1334
1335class B
1336{
1337 public $b = 'foo';
1338}
const EOL
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
const EOF
How fgetc() reports an End Of File.
Definition: JSMin_lib.php:92
$test
Definition: Utf8Test.php:84
$files
Definition: add-vimline.php:18
$comment
Definition: buildRTE.php:83
An exception for terminatinating execution or to throw for unit testing.
Parser parses YAML strings to convert them to PHP arrays.
Definition: Parser.php:22
testObjectsSupportDisabledWithExceptions($yaml)
@dataProvider invalidDumpedObjectProvider @expectedException \Symfony\Component\Yaml\Exception\ParseE...
Definition: ParserTest.php:547
testObjectForMap($yaml, $expected)
@dataProvider getObjectForMapTests
Definition: ParserTest.php:466
testMappingDuplicateKeyBlock()
‍It is an error for two equal keys to appear in the same mapping node.
Definition: ParserTest.php:753
testParseBinaryData($data)
@dataProvider getBinaryData
testUnindentedCollectionException()
@expectedException \Symfony\Component\Yaml\Exception\ParseException
Definition: ParserTest.php:604
testMultipleDocumentsNotSupportedException()
@expectedException \Symfony\Component\Yaml\Exception\ParseException @expectedExceptionMessageRegExp /...
Definition: ParserTest.php:638
testParseInvalidBinaryData($data, $expectedMessage)
@dataProvider getInvalidBinaryData
testNonUtf8Exception()
@requires extension iconv
Definition: ParserTest.php:582
testCommentLikeStringsAreNotStrippedInBlockScalars($yaml, $expectedParserResult)
@dataProvider getCommentLikeStringInScalarBlockData
Definition: ParserTest.php:990
testBlockLiteralWithLeadingNewlines()
Regression test for issue #7989.
Definition: ParserTest.php:406
testObjectSupportEnabledWithDeprecatedTag()
@group legacy
Definition: ParserTest.php:446
testParserThrowsExceptionWithCorrectLineNumber($lineNumber, $yaml)
testObjectForMapEnabledWithMappingUsingBooleanToggles($yaml, $expected)
@group legacy @dataProvider getObjectForMapTests
Definition: ParserTest.php:475
testObjectsSupportDisabledWithExceptionsUsingBooleanToggles($yaml)
@group legacy @dataProvider invalidDumpedObjectProvider @expectedException \Symfony\Component\Yaml\Ex...
Definition: ParserTest.php:557
testObjectSupportDisabledButNoExceptions($input)
@dataProvider invalidDumpedObjectProvider
Definition: ParserTest.php:458
testShortcutKeyUnindentedCollectionException()
@expectedException \Symfony\Component\Yaml\Exception\ParseException
Definition: ParserTest.php:621
testBlockChomping($expected, $yaml)
@dataProvider getBlockChompingTests
Definition: ParserTest.php:396
testObjectSupportEnabledPassingTrue()
@group legacy
Definition: ParserTest.php:434
testColonInMappingValueException()
@expectedException \Symfony\Component\Yaml\Exception\ParseException @expectedExceptionMessage A colon...
Definition: ParserTest.php:968
testScalarInSequence()
@expectedException \Symfony\Component\Yaml\Exception\ParseException @expectedExceptionMessage missing...
Definition: ParserTest.php:732
testSpecifications($file, $expected, $yaml, $comment)
@dataProvider getDataFormSpecifications
Definition: ParserTest.php:34
testMappingInASequence()
@expectedException \Symfony\Component\Yaml\Exception\ParseException
Definition: ParserTest.php:718
testSequenceInAMapping()
@expectedException \Symfony\Component\Yaml\Exception\ParseException
Definition: ParserTest.php:658
Yaml offers convenience methods to load and dump YAML.
Definition: Yaml.php:22
comment()
Definition: comment.php:2
e($cmd)
Definition: flush.php:14
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$this data['403_header']