@@ -1061,6 +1061,97 @@ public static function getDateTimeData()
10611061 ];
10621062 }
10631063
1064+ public static function getDumpCompactNestedMapping ()
1065+ {
1066+ $ data = [
1067+ 'planets ' => [
1068+ [
1069+ 'name ' => 'Mercury ' ,
1070+ 'distance ' => 57910000 ,
1071+ 'properties ' => [
1072+ ['name ' => 'size ' , 'value ' => 4879 ],
1073+ ['name ' => 'moons ' , 'value ' => 0 ],
1074+ [[[]]],
1075+ ],
1076+ ],
1077+ [
1078+ 'name ' => 'Jupiter ' ,
1079+ 'distance ' => 778500000 ,
1080+ 'properties ' => [
1081+ ['name ' => 'size ' , 'value ' => 139820 ],
1082+ ['name ' => 'moons ' , 'value ' => 79 ],
1083+ [[]],
1084+ ],
1085+ ],
1086+ ],
1087+ ];
1088+ $ expected = <<<YAML
1089+ planets:
1090+ \t- name: Mercury
1091+ \t distance: 57910000
1092+ \t properties:
1093+ \t\t - name: size
1094+ \t\t value: 4879
1095+ \t\t - name: moons
1096+ \t\t value: 0
1097+ \t\t - - - { }
1098+ \t- name: Jupiter
1099+ \t distance: 778500000
1100+ \t properties:
1101+ \t\t - name: size
1102+ \t\t value: 139820
1103+ \t\t - name: moons
1104+ \t\t value: 79
1105+ \t\t - - { }
1106+
1107+ YAML ;
1108+
1109+ for ($ indentation = 1 ; $ indentation < 5 ; ++$ indentation ) {
1110+ yield \sprintf ('Compact nested mapping %d ' , $ indentation ) => [
1111+ $ data ,
1112+ strtr ($ expected , ["\t" => str_repeat (' ' , $ indentation )]),
1113+ $ indentation ,
1114+ ];
1115+ }
1116+
1117+ $ indentation = 2 ;
1118+ $ inline = 4 ;
1119+ $ expected = <<<YAML
1120+ planets:
1121+ - name: Mercury
1122+ distance: 57910000
1123+ properties:
1124+ - { name: size, value: 4879 }
1125+ - { name: moons, value: 0 }
1126+ - [[{ }]]
1127+ - name: Jupiter
1128+ distance: 778500000
1129+ properties:
1130+ - { name: size, value: 139820 }
1131+ - { name: moons, value: 79 }
1132+ - [{ }]
1133+
1134+ YAML ;
1135+
1136+ yield \sprintf ('Compact nested mapping %d and inline %d ' , $ indentation , $ inline ) => [
1137+ $ data ,
1138+ $ expected ,
1139+ $ indentation ,
1140+ $ inline ,
1141+ ];
1142+ }
1143+
1144+ /**
1145+ * @dataProvider getDumpCompactNestedMapping
1146+ */
1147+ public function testDumpCompactNestedMapping (array $ data , string $ expected , int $ indentation , int $ inline = 10 )
1148+ {
1149+ $ dumper = new Dumper ($ indentation );
1150+ $ actual = $ dumper ->dump ($ data , $ inline , 0 , Yaml::DUMP_COMPACT_NESTED_MAPPING );
1151+ $ this ->assertSame ($ expected , $ actual );
1152+ $ this ->assertSameData ($ data , $ this ->parser ->parse ($ actual ));
1153+ }
1154+
10641155 private function assertSameData ($ expected , $ actual )
10651156 {
10661157 $ this ->assertEquals ($ expected , $ actual );
0 commit comments