1414use function fopen ;
1515use function json_encode ;
1616
17+ use const JSON_PRESERVE_ZERO_FRACTION ;
1718use const JSON_THROW_ON_ERROR ;
1819
1920class JsonTest extends TestCase
@@ -62,7 +63,7 @@ public function testJsonEmptyStringConvertsToPHPValue(): void
6263 public function testJsonStringConvertsToPHPValue (): void
6364 {
6465 $ value = ['foo ' => 'bar ' , 'bar ' => 'foo ' ];
65- $ databaseValue = json_encode ($ value , 0 , JSON_THROW_ON_ERROR );
66+ $ databaseValue = json_encode ($ value , 0 , JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION );
6667 $ phpValue = $ this ->type ->convertToPHPValue ($ databaseValue , $ this ->platform );
6768
6869 self ::assertEquals ($ value , $ phpValue );
@@ -87,7 +88,10 @@ public function testJsonResourceConvertsToPHPValue(): void
8788 {
8889 $ value = ['foo ' => 'bar ' , 'bar ' => 'foo ' ];
8990 $ databaseValue = fopen (
90- 'data://text/plain;base64, ' . base64_encode (json_encode ($ value , JSON_THROW_ON_ERROR )),
91+ 'data://text/plain;base64, ' . base64_encode (json_encode (
92+ $ value ,
93+ JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION
94+ )),
9195 'r '
9296 );
9397 $ phpValue = $ this ->type ->convertToPHPValue ($ databaseValue , $ this ->platform );
@@ -100,6 +104,27 @@ public function testRequiresSQLCommentHint(): void
100104 self ::assertTrue ($ this ->type ->requiresSQLCommentHint ($ this ->platform ));
101105 }
102106
107+ public function testPHPNullValueConvertsToJsonNull (): void
108+ {
109+ self ::assertNull ($ this ->type ->convertToDatabaseValue (null , $ this ->platform ));
110+ }
111+
112+ public function testPHPValueConvertsToJsonString (): void
113+ {
114+ $ source = ['foo ' => 'bar ' , 'bar ' => 'foo ' ];
115+ $ databaseValue = $ this ->type ->convertToDatabaseValue ($ source , $ this ->platform );
116+
117+ self ::assertSame ('{"foo":"bar","bar":"foo"} ' , $ databaseValue );
118+ }
119+
120+ public function testPHPFloatValueConvertsToJsonString (): void
121+ {
122+ $ source = ['foo ' => 11.4 , 'bar ' => 10.0 ];
123+ $ databaseValue = $ this ->type ->convertToDatabaseValue ($ source , $ this ->platform );
124+
125+ self ::assertSame ('{"foo":11.4,"bar":10.0} ' , $ databaseValue );
126+ }
127+
103128 public function testSerializationFailure (): void
104129 {
105130 $ object = (object ) [];
0 commit comments