-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonSerializerEncodingTest.php
More file actions
61 lines (53 loc) · 1.89 KB
/
Copy pathJsonSerializerEncodingTest.php
File metadata and controls
61 lines (53 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Tests\Koded\Stdlib\Serializer;
use Koded\Stdlib\Serializer\JsonSerializer;
use PHPUnit\Framework\TestCase;
use function Koded\Stdlib\json_serialize;
class JsonSerializerEncodingTest extends TestCase
{
public function test_serialize_without_unescaped_unicode_option()
{
$this->assertEquals(
'{"diva":"Björk Guðmundsdóttir"}',
(new JsonSerializer)
->serialize(require __DIR__ . '/../fixtures/utf8-file.php')
);
}
public function test_function_serialize_without_unescaped_unicode_option()
{
$this->assertEquals(
'{"diva":"Björk Guðmundsdóttir"}',
json_serialize(require __DIR__ . '/../fixtures/utf8-file.php')
);
}
public function test_serialize_with_unescaped_unicode_option()
{
$this->assertEquals(
'{"diva":"Bj\u00f6rk Gu\u00f0mundsd\u00f3ttir"}',
(new JsonSerializer(JSON_UNESCAPED_UNICODE))
->serialize(require __DIR__ . '/../fixtures/utf8-file.php')
);
}
public function test_function_serialize_with_unescaped_unicode_option()
{
$this->assertEquals(
'{"diva":"Bj\u00f6rk Gu\u00f0mundsd\u00f3ttir"}',
json_serialize(
require __DIR__ . '/../fixtures/utf8-file.php',
JSON_UNESCAPED_UNICODE
)
);
}
public function test_should_not_convert_to_int()
{
$this->assertSame(
'{"phone":"+1234567890"}',
(new JsonSerializer)->serialize(['phone' => '+1234567890'])
);
}
public function test_fails_for_serialize_because_php_brilliant_utf8_requirement()
{
$actual = (new JsonSerializer)->serialize(require __DIR__ . '/../fixtures/non-utf8-file.php');
$this->assertSame('', $actual, 'json_encode() failed to encode the data (non UTF-8 content)');
}
}