@@ 77-97 (lines=21) @@ | ||
74 | $client->getLocations(); |
|
75 | } |
|
76 | ||
77 | public function testMalformedJsonError() |
|
78 | { |
|
79 | $invalidResponse = <<<JSON |
|
80 | {{{{{{{ |
|
81 | JSON; |
|
82 | ||
83 | $mockRequests = [ |
|
84 | new Response(200, ['Content-type' => 'application/json'], $invalidResponse), |
|
85 | ]; |
|
86 | $mockHandler = new MockHandler($mockRequests); |
|
87 | $handler = HandlerStack::create($mockHandler); |
|
88 | $httpClient = new GuzzleClient(['handler' => $handler]); |
|
89 | ||
90 | $request = new Request('GET', 'http://localhost/', array('Accept' => 'application/json')); |
|
91 | ||
92 | $client = new Client($httpClient, $request); |
|
93 | ||
94 | $this->setExpectedException('Symfony\Component\Serializer\Exception\UnexpectedValueException'); |
|
95 | ||
96 | $client->getLocations(); |
|
97 | } |
|
98 | ||
99 | public function testMalformedDataError1() |
|
100 | { |
|
@@ 99-123 (lines=25) @@ | ||
96 | $client->getLocations(); |
|
97 | } |
|
98 | ||
99 | public function testMalformedDataError1() |
|
100 | { |
|
101 | $validResponse = <<<JSON |
|
102 | { |
|
103 | "data": { |
|
104 | "locations": [] |
|
105 | } |
|
106 | } |
|
107 | JSON; |
|
108 | ||
109 | $mockRequests = [ |
|
110 | new Response(200, ['Content-type' => 'application/json'], $validResponse), |
|
111 | ]; |
|
112 | $mockHandler = new MockHandler($mockRequests); |
|
113 | $handler = HandlerStack::create($mockHandler); |
|
114 | $httpClient = new GuzzleClient(['handler' => $handler]); |
|
115 | ||
116 | $request = new Request('GET', 'http://localhost/', array('Accept' => 'application/json')); |
|
117 | ||
118 | $client = new Client($httpClient, $request); |
|
119 | ||
120 | $this->setExpectedException('AlexeyKuperhstokh\LocationBundle\Exceptions\MalformedDataException'); |
|
121 | ||
122 | $client->getLocations(); |
|
123 | } |
|
124 | ||
125 | public function testMalformedDataError2() |
|
126 | { |
|
@@ 125-150 (lines=26) @@ | ||
122 | $client->getLocations(); |
|
123 | } |
|
124 | ||
125 | public function testMalformedDataError2() |
|
126 | { |
|
127 | $validResponse = <<<JSON |
|
128 | { |
|
129 | "data": { |
|
130 | "locations": 1 |
|
131 | }, |
|
132 | "success": true |
|
133 | } |
|
134 | JSON; |
|
135 | ||
136 | $mockRequests = [ |
|
137 | new Response(200, ['Content-type' => 'application/json'], $validResponse), |
|
138 | ]; |
|
139 | $mockHandler = new MockHandler($mockRequests); |
|
140 | $handler = HandlerStack::create($mockHandler); |
|
141 | $httpClient = new GuzzleClient(['handler' => $handler]); |
|
142 | ||
143 | $request = new Request('GET', 'http://localhost/', array('Accept' => 'application/json')); |
|
144 | ||
145 | $client = new Client($httpClient, $request); |
|
146 | ||
147 | $this->setExpectedException('AlexeyKuperhstokh\LocationBundle\Exceptions\MalformedDataException'); |
|
148 | ||
149 | $client->getLocations(); |
|
150 | } |
|
151 | ||
152 | public function testServerErrorException() |
|
153 | { |
|
@@ 152-182 (lines=31) @@ | ||
149 | $client->getLocations(); |
|
150 | } |
|
151 | ||
152 | public function testServerErrorException() |
|
153 | { |
|
154 | $validResponse = <<<JSON |
|
155 | { |
|
156 | "data": { |
|
157 | "message": "testMessage", |
|
158 | "code": 100 |
|
159 | }, |
|
160 | "success": false |
|
161 | } |
|
162 | JSON; |
|
163 | ||
164 | $mockRequests = [ |
|
165 | new Response(200, ['Content-type' => 'application/json'], $validResponse), |
|
166 | ]; |
|
167 | $mockHandler = new MockHandler($mockRequests); |
|
168 | $handler = HandlerStack::create($mockHandler); |
|
169 | $httpClient = new GuzzleClient(['handler' => $handler]); |
|
170 | ||
171 | $request = new Request('GET', 'http://localhost/', array('Accept' => 'application/json')); |
|
172 | ||
173 | $client = new Client($httpClient, $request); |
|
174 | ||
175 | $this->setExpectedException( |
|
176 | 'AlexeyKuperhstokh\LocationBundle\Exceptions\ServerErrorException', |
|
177 | 'testMessage', |
|
178 | 100 |
|
179 | ); |
|
180 | ||
181 | $client->getLocations(); |
|
182 | } |
|
183 | } |
|
184 |