File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1212
1313class ObjectDriver implements Driver
1414{
15+ public function __construct (
16+ protected int $ yamlInline = 2 ,
17+ ) {
18+ }
19+
1520 public function serialize ($ data ): string
1621 {
1722 $ normalizers = [
@@ -27,7 +32,7 @@ public function serialize($data): string
2732
2833 return $ this ->dedent (
2934 $ serializer ->serialize ($ data , 'yaml ' , [
30- 'yaml_inline ' => 2 ,
35+ 'yaml_inline ' => $ this -> yamlInline ,
3136 'yaml_indent ' => 4 ,
3237 'yaml_flags ' => Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK ,
3338 ])
Original file line number Diff line number Diff line change @@ -88,6 +88,27 @@ public function it_can_serialize_a_class_instance()
8888
8989 $ this ->assertEquals ($ expected , $ driver ->serialize (new Obj ));
9090 }
91+
92+ #[Test]
93+ public function it_can_serialize_with_custom_parameters ()
94+ {
95+ $ driver = new ObjectDriver (3 );
96+
97+ $ nestedObject = (object ) [
98+ 'foo ' => (object ) [
99+ 'bar ' => (object ) [
100+ 'baz ' => ['qux ' , 'quux ' ],
101+ ],
102+ ],
103+ ];
104+ $ expected = implode ("\n" , [
105+ 'foo: ' ,
106+ ' bar: ' ,
107+ ' baz: [qux, quux] ' ,
108+ '' ,
109+ ]);
110+ $ this ->assertEquals ($ expected , $ driver ->serialize ($ nestedObject ));
111+ }
91112}
92113
93114class Obj
You can’t perform that action at this time.
0 commit comments