@@ -65,6 +65,47 @@ public function testOptions()
65
65
$ this ->assertEquals ($ expected , $ this ->serializer ->serialize ($ arr , 'json ' ), 'Context should not be persistent ' );
66
66
}
67
67
68
+ /**
69
+ * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
70
+ */
71
+ public function testEncodeNotUtf8WithoutPartialOnError ()
72
+ {
73
+ $ arr = array (
74
+ 'utf8 ' => 'Hello World! ' ,
75
+ 'notUtf8 ' => "\xb0\xd0\xb5\xd0" ,
76
+ );
77
+
78
+ $ this ->encoder ->encode ($ arr , 'json ' );
79
+ }
80
+
81
+ /**
82
+ * @requires PHP 5.5
83
+ */
84
+ public function testEncodeNotUtf8WithPartialOnError ()
85
+ {
86
+ $ context = array ('json_encode_options ' => JSON_PARTIAL_OUTPUT_ON_ERROR );
87
+
88
+ $ arr = array (
89
+ 'utf8 ' => 'Hello World! ' ,
90
+ 'notUtf8 ' => "\xb0\xd0\xb5\xd0" ,
91
+ );
92
+
93
+ $ result = $ this ->encoder ->encode ($ arr , 'json ' , $ context );
94
+ $ jsonLastError = json_last_error ();
95
+
96
+ $ this ->assertSame (JSON_ERROR_UTF8 , $ jsonLastError );
97
+ $ this ->assertEquals ('{"utf8":"Hello World!","notUtf8":null} ' , $ result );
98
+
99
+ $ this ->assertEquals ('0 ' , $ this ->serializer ->serialize (NAN , 'json ' , $ context ));
100
+ }
101
+
102
+ public function testDecodeFalseString ()
103
+ {
104
+ $ result = $ this ->encoder ->decode ('false ' , 'json ' );
105
+ $ this ->assertSame (JSON_ERROR_NONE , json_last_error ());
106
+ $ this ->assertFalse ($ result );
107
+ }
108
+
68
109
protected function getJsonSource ()
69
110
{
70
111
return '{"foo":"foo","bar":["a","b"],"baz":{"key":"val","key2":"val","A B":"bar","item":[{"title":"title1"},{"title":"title2"}],"Barry":{"FooBar":{"Baz":"Ed","@id":1}}},"qux":"1"} ' ;
0 commit comments