-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonSerializerFunctionsTest.php
More file actions
86 lines (75 loc) · 2.36 KB
/
Copy pathJsonSerializerFunctionsTest.php
File metadata and controls
86 lines (75 loc) · 2.36 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Tests\Koded\Stdlib;
use PHPUnit\Framework\TestCase;
use Tests\Koded\Stdlib\Serializer\JsonSerializerTest;
use function Koded\Stdlib\{json_serialize, json_unserialize};
class JsonSerializerFunctionsTest extends TestCase
{
/**
* @dataProvider data
*/
public function test_serialize_to_json($data)
{
$this->assertEquals(JsonSerializerTest::SERIALIZED_JSON, json_encode($data));
}
public function test_unserialize_json()
{
$this->assertEquals(
json_decode(JsonSerializerTest::SERIALIZED_JSON, false),
json_unserialize(JsonSerializerTest::SERIALIZED_JSON)
);
}
public function test_unserialize_error()
{
$this->assertSame('', json_unserialize(''),
'Returns empty string on JSON decoding fails');
}
/**
* @dataProvider options
*/
public function test_unicode_without_json_unicode_flag($data)
{
$serialized = json_serialize($data, JSON_UNESCAPED_UNICODE);
$unserialized = json_unserialize($serialized, true);
$this->assertSame(
<<<'JSON'
["1",1,"2.01",2.01,"Bj\\u00f6rk Gu\\u00f0mundsd\\u00f3ttir","Bj\u00f6rk Gu\u00f0mundsd\u00f3ttir","Bj\\u00f6rk Gu\u00f0mundsd\u00f3ttir","\\//",true,false]
JSON,
$serialized,
'Transforms unicode characters into unicode representation, keep the rest intact'
);
$this->assertEquals($data, $unserialized);
}
/**
* @dataProvider options
*/
public function test_unicode_with_default_options($data)
{
$serialized = json_serialize($data);
$unserialized = json_unserialize($serialized, true);
$this->assertSame(
<<<'JSON'
["1",1,"2.01",2.01,"Bj\\u00f6rk Gu\\u00f0mundsd\\u00f3ttir","Björk Guðmundsdóttir","Bj\\u00f6rk Guðmundsdóttir","\\//",true,false]
JSON,
$serialized,
'Keep the unicode characters as-is'
);
$this->assertEquals($data, $unserialized);
}
public function data()
{
return [
[
require __DIR__ . '/fixtures/config-test.php'
]
];
}
public function options()
{
return [
[
require __DIR__ . '/fixtures/serializer-options.php'
]
];
}
}