|
16 | 16 | use Prophecy\Argument; |
17 | 17 | use Psr\Http\Message\RequestInterface; |
18 | 18 | use Zend\Diactoros\Response; |
| 19 | +use Nexmo\Client\Exception; |
19 | 20 |
|
20 | 21 | class CollectionTest extends \PHPUnit_Framework_TestCase |
21 | 22 | { |
@@ -132,6 +133,63 @@ public function testCreatePostCall($payload, $method) |
132 | 133 | $this->assertInstanceOf('Nexmo\Call\Call', $call); |
133 | 134 | $this->assertEquals('e46fd8bd-504d-4044-9600-26dd18b41111', $call->getId()); |
134 | 135 | } |
| 136 | + |
| 137 | + /** |
| 138 | + * @dataProvider postCall |
| 139 | + */ |
| 140 | + public function testCreatePostCallErrorFromVApi($payload, $method) |
| 141 | + { |
| 142 | + $this->nexmoClient->send(Argument::that(function(RequestInterface $request) use ($payload){ |
| 143 | + $this->assertRequestUrl('api.nexmo.com', '/v1/calls', 'POST', $request); |
| 144 | + $this->assertRequestBodyIsJson(json_encode($payload), $request); |
| 145 | + return true; |
| 146 | + }))->willReturn($this->getResponse('error_vapi', '400')); |
| 147 | + |
| 148 | + try { |
| 149 | + $call = $this->collection->$method($payload); |
| 150 | + $this->fail('Expected to throw request exception'); |
| 151 | + } catch (Exception\Request $e) { |
| 152 | + $this->assertEquals($e->getMessage(), 'Bad Request'); |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * @dataProvider postCall |
| 158 | + */ |
| 159 | + public function testCreatePostCallErrorFromProxy($payload, $method) |
| 160 | + { |
| 161 | + $this->nexmoClient->send(Argument::that(function(RequestInterface $request) use ($payload){ |
| 162 | + $this->assertRequestUrl('api.nexmo.com', '/v1/calls', 'POST', $request); |
| 163 | + $this->assertRequestBodyIsJson(json_encode($payload), $request); |
| 164 | + return true; |
| 165 | + }))->willReturn($this->getResponse('error_proxy', '400')); |
| 166 | + |
| 167 | + try { |
| 168 | + $call = $this->collection->$method($payload); |
| 169 | + $this->fail('Expected to throw request exception'); |
| 170 | + } catch (Exception\Request $e) { |
| 171 | + $this->assertEquals($e->getMessage(), 'Unsupported Media Type'); |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + /** |
| 176 | + * @dataProvider postCall |
| 177 | + */ |
| 178 | + public function testCreatePostCallErrorUnknownFormat($payload, $method) |
| 179 | + { |
| 180 | + $this->nexmoClient->send(Argument::that(function(RequestInterface $request) use ($payload){ |
| 181 | + $this->assertRequestUrl('api.nexmo.com', '/v1/calls', 'POST', $request); |
| 182 | + $this->assertRequestBodyIsJson(json_encode($payload), $request); |
| 183 | + return true; |
| 184 | + }))->willReturn($this->getResponse('error_unknown_format', '400')); |
| 185 | + |
| 186 | + try { |
| 187 | + $call = $this->collection->$method($payload); |
| 188 | + $this->fail('Expected to throw request exception'); |
| 189 | + } catch (Exception\Request $e) { |
| 190 | + $this->assertEquals($e->getMessage(), "Unexpected error"); |
| 191 | + } |
| 192 | + } |
135 | 193 |
|
136 | 194 | /** |
137 | 195 | * @dataProvider putCall |
|
0 commit comments