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 12
12
13
13
class ObjectDriver implements Driver
14
14
{
15
+ public function __construct (
16
+ protected int $ yamlInline = 2 ,
17
+ ) {
18
+ }
19
+
15
20
public function serialize ($ data ): string
16
21
{
17
22
$ normalizers = [
@@ -27,7 +32,7 @@ public function serialize($data): string
27
32
28
33
return $ this ->dedent (
29
34
$ serializer ->serialize ($ data , 'yaml ' , [
30
- 'yaml_inline ' => 2 ,
35
+ 'yaml_inline ' => $ this -> yamlInline ,
31
36
'yaml_indent ' => 4 ,
32
37
'yaml_flags ' => Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK ,
33
38
])
Original file line number Diff line number Diff line change @@ -88,6 +88,27 @@ public function it_can_serialize_a_class_instance()
88
88
89
89
$ this ->assertEquals ($ expected , $ driver ->serialize (new Obj ));
90
90
}
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
+ }
91
112
}
92
113
93
114
class Obj
You can’t perform that action at this time.
0 commit comments