1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
require_once __DIR__ . '/Expectation/Json.php'; |
4
|
|
|
require_once __DIR__ . '/Expectation/Object.php'; |
5
|
|
|
|
6
|
|
|
use GroupByInc\API\Util\SerializerFactory; |
7
|
|
|
use JMS\Serializer\Serializer; |
8
|
|
|
|
9
|
|
|
class JsonSerializeTest extends PHPUnit_Framework_TestCase |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** @var Serializer */ |
13
|
|
|
private static $serializer; |
14
|
|
|
|
15
|
|
|
public static function setUpBeforeClass() |
16
|
|
|
{ |
17
|
|
|
self::$serializer = SerializerFactory::build(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @param object $obj |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
private function serialize($obj) |
26
|
|
|
{ |
27
|
|
|
return self::$serializer->serialize($obj, 'json'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testEncodePageInfo() |
31
|
|
|
{ |
32
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$PAGE_INFO, |
33
|
|
|
$this->serialize(Object::$PAGE_INFO)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testEncodeCluster() |
37
|
|
|
{ |
38
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$CLUSTER, |
39
|
|
|
$this->serialize(Object::$CLUSTER)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testEncodeClusterRecord() |
43
|
|
|
{ |
44
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$CLUSTER_RECORD, |
45
|
|
|
$this->serialize(Object::$CLUSTER_RECORD)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testEncodeCustomUrlParam() |
49
|
|
|
{ |
50
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$CUSTOM_URL_PARAM, |
51
|
|
|
$this->serialize(Object::$CUSTOM_URL_PARAM)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testEncodeMetadata() |
55
|
|
|
{ |
56
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$METADATA, |
57
|
|
|
$this->serialize(Object::$METADATA)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testEncodeNavigation() |
61
|
|
|
{ |
62
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$NAVIGATION, |
63
|
|
|
$this->serialize(Object::$NAVIGATION)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testEncodeRefinementMatchValue() |
67
|
|
|
{ |
68
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$REFINEMENT_MATCH_VALUE, |
69
|
|
|
$this->serialize(Object::$REFINEMENT_MATCH_VALUE)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testEncodeRefinementMatch() |
73
|
|
|
{ |
74
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$REFINEMENT_MATCH, |
75
|
|
|
$this->serialize(Object::$REFINEMENT_MATCH)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testEncodeRecord() |
79
|
|
|
{ |
80
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$RECORD, |
81
|
|
|
$this->serialize(Object::$RECORD)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testEncodeRefinementRange() |
85
|
|
|
{ |
86
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$REFINEMENT_RANGE, |
87
|
|
|
$this->serialize(Object::$REFINEMENT_RANGE)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testEncodeRefinementValue() |
91
|
|
|
{ |
92
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$REFINEMENT_VALUE, |
93
|
|
|
$this->serialize(Object::$REFINEMENT_VALUE)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testEncodeContentZone() |
97
|
|
|
{ |
98
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$CONTENT_ZONE, |
99
|
|
|
$this->serialize(Object::$CONTENT_ZONE)); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testEncodeBannerZone() |
103
|
|
|
{ |
104
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$BANNER_ZONE, |
105
|
|
|
$this->serialize(Object::$BANNER_ZONE)); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testEncodeRichContentZone() |
109
|
|
|
{ |
110
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$RICH_CONTENT_ZONE, |
111
|
|
|
$this->serialize(Object::$RICH_CONTENT_ZONE)); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testEncodeRecordZone() |
115
|
|
|
{ |
116
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$RECORD_ZONE, |
117
|
|
|
$this->serialize(Object::$RECORD_ZONE)); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function testEncodeSort() |
121
|
|
|
{ |
122
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$SORT, $this->serialize(Object::$SORT)); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testEncodeTemplate() |
126
|
|
|
{ |
127
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$TEMPLATE, |
128
|
|
|
$this->serialize(Object::$TEMPLATE)); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function testEncodeRestrictNavigation() |
132
|
|
|
{ |
133
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$RESTRICT_NAVIGATION, |
134
|
|
|
$this->serialize(Object::$RESTRICT_NAVIGATION)); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function testEncodePartialMatchRule() |
138
|
|
|
{ |
139
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$PARTIAL_MATCH_RULE, |
140
|
|
|
$this->serialize(Object::$PARTIAL_MATCH_RULE)); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testEncodeMatchStrategy() |
144
|
|
|
{ |
145
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$MATCH_STRATEGY, |
146
|
|
|
$this->serialize(Object::$MATCH_STRATEGY)); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testEncodeBiasing() |
150
|
|
|
{ |
151
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$BIASING, $this->serialize(Object::$BIASING)); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testEncodeRequest() |
155
|
|
|
{ |
156
|
|
|
$this->assertJsonStringEqualsJsonString(Json::$REQUEST, $this->serialize(Object::$REQUEST)); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testEncodeRefinementsRequest() |
160
|
|
|
{ |
161
|
|
|
$this->assertJsonStringEqualsJsonString(JSON::$REFINEMENTS_REQUEST, |
162
|
|
|
$this->serialize(Object::$REFINEMENTS_REQUEST)); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.