-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonSerializerOptionsTest.php
More file actions
72 lines (59 loc) · 2.34 KB
/
Copy pathJsonSerializerOptionsTest.php
File metadata and controls
72 lines (59 loc) · 2.34 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
<?php
namespace Tests\Koded\Stdlib\Serializer;
use Koded\Stdlib\Serializer\JsonSerializer;
use PHPUnit\Framework\TestCase;
use Tests\Koded\Stdlib\ObjectPropertyTrait;
/**
* Tests for the constructor.
*/
class JsonSerializerOptionsTest extends TestCase
{
use ObjectPropertyTrait;
public function test_default_options()
{
$expected = JSON_PRESERVE_ZERO_FRACTION
| JSON_UNESCAPED_SLASHES
| JSON_UNESCAPED_UNICODE
| JSON_THROW_ON_ERROR;
$this->assertEquals(
$expected,
$this->property(new JsonSerializer, 'options')
);
}
public function test_adding_options()
{
$expected = JSON_PRESERVE_ZERO_FRACTION
| JSON_UNESCAPED_SLASHES
| JSON_UNESCAPED_UNICODE
| JSON_PRETTY_PRINT
| JSON_ERROR_INF_OR_NAN
| JSON_THROW_ON_ERROR;
$this->assertEquals(
$expected,
$this->property(new JsonSerializer(JSON_ERROR_INF_OR_NAN | JSON_PRETTY_PRINT), 'options')
);
}
public function test_excluding_options()
{
$expected = JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_UNICODE;
$this->assertEquals(
$expected,
$this->property(new JsonSerializer(JSON_UNESCAPED_SLASHES ^ JSON_THROW_ON_ERROR), 'options')
);
}
public function test_include_and_exclude_options()
{
$expected = JSON_NUMERIC_CHECK
| JSON_UNESCAPED_SLASHES
| JSON_THROW_ON_ERROR;
$this->assertEquals($expected, $this->property(new JsonSerializer(
JSON_UNESCAPED_UNICODE ^ JSON_PRESERVE_ZERO_FRACTION | JSON_NUMERIC_CHECK
), 'options'), 'Adds JSON_NUMERIC_CHECK, but removes JSON_UNESCAPED_UNICODE and JSON_PRESERVE_ZERO_FRACTION');
$this->assertEquals($expected, $this->property(new JsonSerializer(
JSON_PRESERVE_ZERO_FRACTION | JSON_NUMERIC_CHECK ^ JSON_UNESCAPED_UNICODE
), 'options'), 'Adds JSON_NUMERIC_CHECK, but removes JSON_UNESCAPED_UNICODE and JSON_PRESERVE_ZERO_FRACTION');
$this->assertEquals($expected, $this->property(new JsonSerializer(
JSON_NUMERIC_CHECK ^ JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_UNICODE
), 'options'), 'Adds JSON_NUMERIC_CHECK, but removes JSON_UNESCAPED_UNICODE and JSON_PRESERVE_ZERO_FRACTION');
}
}