@@ -442,35 +442,75 @@ public function testObjectSupportDisabledButNoExceptions($input)
442
442
$ this ->assertEquals (array ('foo ' => null , 'bar ' => 1 ), $ this ->parser ->parse ($ input ), '->parse() does not parse objects ' );
443
443
}
444
444
445
- public function testObjectForMapEnabledWithMapping ()
445
+ /**
446
+ * @dataProvider getObjectForMapTests
447
+ */
448
+ public function testObjectForMap ($ yaml , $ expected )
449
+ {
450
+ $ this ->assertEquals ($ expected , $ this ->parser ->parse ($ yaml , false , false , true ));
451
+ }
452
+
453
+ public function getObjectForMapTests ()
446
454
{
455
+ $ tests = array ();
456
+
447
457
$ yaml = <<<EOF
448
458
foo:
449
459
fiz: [cat]
450
460
EOF ;
451
- $ result = $ this ->parser ->parse ($ yaml , false , false , true );
452
-
453
- $ this ->assertInstanceOf ('stdClass ' , $ result );
454
- $ this ->assertInstanceOf ('stdClass ' , $ result ->foo );
455
- $ this ->assertEquals (array ('cat ' ), $ result ->foo ->fiz );
456
- }
457
-
458
- public function testObjectForMapEnabledWithInlineMapping ()
459
- {
460
- $ result = $ this ->parser ->parse ('{ "foo": "bar", "fiz": "cat" } ' , false , false , true );
461
+ $ expected = new \stdClass ();
462
+ $ expected ->foo = new \stdClass ();
463
+ $ expected ->foo ->fiz = array ('cat ' );
464
+ $ tests ['mapping ' ] = array ($ yaml , $ expected );
461
465
462
- $ this ->assertInstanceOf ('stdClass ' , $ result );
463
- $ this ->assertEquals ('bar ' , $ result ->foo );
464
- $ this ->assertEquals ('cat ' , $ result ->fiz );
465
- }
466
+ $ yaml = '{ "foo": "bar", "fiz": "cat" } ' ;
467
+ $ expected = new \stdClass ();
468
+ $ expected ->foo = 'bar ' ;
469
+ $ expected ->fiz = 'cat ' ;
470
+ $ tests ['inline-mapping ' ] = array ($ yaml , $ expected );
466
471
467
- public function testObjectForMapIsAppliedAfterParsing ()
468
- {
472
+ $ yaml = "foo: bar \nbaz: foobar " ;
469
473
$ expected = new \stdClass ();
470
474
$ expected ->foo = 'bar ' ;
471
475
$ expected ->baz = 'foobar ' ;
476
+ $ tests ['object-for-map-is-applied-after-parsing ' ] = array ($ yaml , $ expected );
472
477
473
- $ this ->assertEquals ($ expected , $ this ->parser ->parse ("foo: bar \nbaz: foobar " , false , false , true ));
478
+ $ yaml = <<<EOT
479
+ array:
480
+ - key: one
481
+ - key: two
482
+ EOT ;
483
+ $ expected = new \stdClass ();
484
+ $ expected ->array = array ();
485
+ $ expected ->array [0 ] = new \stdClass ();
486
+ $ expected ->array [0 ]->key = 'one ' ;
487
+ $ expected ->array [1 ] = new \stdClass ();
488
+ $ expected ->array [1 ]->key = 'two ' ;
489
+ $ tests ['nest-map-and-sequence ' ] = array ($ yaml , $ expected );
490
+
491
+ $ yaml = <<<YAML
492
+ map:
493
+ 1: one
494
+ 2: two
495
+ YAML ;
496
+ $ expected = new \stdClass ();
497
+ $ expected ->map = new \stdClass ();
498
+ $ expected ->map ->{1 } = 'one ' ;
499
+ $ expected ->map ->{2 } = 'two ' ;
500
+ $ tests ['numeric-keys ' ] = array ($ yaml , $ expected );
501
+
502
+ $ yaml = <<<YAML
503
+ map:
504
+ 0: one
505
+ 1: two
506
+ YAML ;
507
+ $ expected = new \stdClass ();
508
+ $ expected ->map = new \stdClass ();
509
+ $ expected ->map ->{0 } = 'one ' ;
510
+ $ expected ->map ->{1 } = 'two ' ;
511
+ $ tests ['zero-indexed-numeric-keys ' ] = array ($ yaml , $ expected );
512
+
513
+ return $ tests ;
474
514
}
475
515
476
516
/**
0 commit comments