Total Complexity | 4 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class JsonSerializerEncodingTest extends TestCase |
||
8 | { |
||
9 | |||
10 | public function test_serialize_without_unicode_option() |
||
11 | { |
||
12 | $this->assertEquals( |
||
13 | '{"diva":"Bj\u00f6rk Gu\u00f0mundsd\u00f3ttir"}', |
||
14 | (new JsonSerializer(JSON_UNESCAPED_SLASHES))->serialize(require __DIR__ . '/../fixtures/utf8-file.php') |
||
15 | ); |
||
16 | } |
||
17 | |||
18 | public function test_serialize_with_unicode_option() |
||
19 | { |
||
20 | $this->assertEquals( |
||
21 | '{"diva":"Björk Guðmundsdóttir"}', |
||
22 | (new JsonSerializer(JSON_UNESCAPED_UNICODE))->serialize(require __DIR__ . '/../fixtures/utf8-file.php') |
||
23 | ); |
||
24 | } |
||
25 | |||
26 | public function test_should_not_convert_to_int() |
||
27 | { |
||
28 | $this->assertSame('{"phone":"+1234567890"}', (new JsonSerializer)->serialize(['phone' => '+1234567890'])); |
||
29 | } |
||
30 | |||
31 | public function test_fails_for_serialize_because_php_brilliant_utf8_requirement() |
||
32 | { |
||
33 | $actual = (new JsonSerializer)->serialize(require __DIR__ . '/../fixtures/non-utf8-file.php'); |
||
34 | $this->assertSame('', $actual, 'json_encode() failed to encode the data (non UTF-8 content)'); |
||
35 | } |
||
37 |