@@ -109,6 +109,48 @@ public function testGenerate()
109
109
self ::assertCount (2 , $ result );
110
110
}
111
111
112
+ public function testGeneratePreservesZeroFraction ()
113
+ {
114
+ $ expectedResult = [
115
+ 'name.space.TestClass ' => json_encode ([
116
+ 'type ' => 'record ' ,
117
+ 'name ' => 'TestClass ' ,
118
+ 'namespace ' => 'name.space ' ,
119
+ 'fields ' => [
120
+ [
121
+ 'name ' => 'name ' ,
122
+ 'type ' => 'double ' ,
123
+ 'default ' => 0.0 ,
124
+ 'doc ' => 'test ' ,
125
+ 'logicalType ' => 'test '
126
+ ]
127
+ ]
128
+ ], JSON_PRESERVE_ZERO_FRACTION )
129
+ ];
130
+
131
+ $ property = $ this ->getMockForAbstractClass (PhpClassPropertyInterface::class);
132
+ $ property ->expects (self ::exactly (1 ))->method ('getPropertyType ' )->willReturn ('double ' );
133
+ $ property ->expects (self ::exactly (1 ))->method ('getPropertyName ' )->willReturn ('name ' );
134
+ $ property ->expects (self ::exactly (2 ))->method ('getPropertyDefault ' )->willReturn (0.0 );
135
+ $ property ->expects (self ::exactly (3 ))->method ('getPropertyDoc ' )->willReturn ('test ' );
136
+ $ property ->expects (self ::exactly (2 ))->method ('getPropertyLogicalType ' )->willReturn ('test ' );
137
+
138
+
139
+ $ class = $ this ->getMockForAbstractClass (PhpClassInterface::class);
140
+ $ class ->expects (self ::once ())->method ('getClassName ' )->willReturn ('TestClass ' );
141
+ $ class ->expects (self ::exactly (2 ))->method ('getClassNamespace ' )->willReturn ('name \\space ' );
142
+ $ class ->expects (self ::once ())->method ('getClassProperties ' )->willReturn ([$ property ]);
143
+
144
+ $ registry = $ this ->getMockForAbstractClass (ClassRegistryInterface::class);
145
+ $ registry ->expects (self ::once ())->method ('getClasses ' )->willReturn ([$ class ]);
146
+
147
+ $ generator = new SchemaGenerator ();
148
+ $ generator ->setClassRegistry ($ registry );
149
+ $ result = $ generator ->generate ();
150
+ self ::assertEquals ($ expectedResult , $ result );
151
+ self ::assertCount (1 , $ result );
152
+ }
153
+
112
154
public function testExportSchemas ()
113
155
{
114
156
$ schemas = [
0 commit comments