@@ -41,7 +41,7 @@ public function testUpdateNumber($payload, $id, $expectedId, $lookup)
4141 {
4242 //based on the id provided, may need to look up the number first
4343 if ($ lookup ){
44- if (is_null ($ id ) OR ('12404284163 ' == $ id )){
44+ if (is_null ($ id ) OR ('1415550100 ' == $ id )){
4545 $ first = $ this ->getResponse ('single ' );
4646 } else {
4747 $ first = $ this ->getResponse ('single-update ' );
@@ -101,30 +101,30 @@ public function updateNumber()
101101 ];
102102
103103 $ rawId ['country ' ] = 'US ' ;
104- $ rawId ['msisdn ' ] = '12404284163 ' ;
104+ $ rawId ['msisdn ' ] = '1415550100 ' ;
105105
106- $ number = new Number ('12404284163 ' );
106+ $ number = new Number ('1415550100 ' );
107107 $ number ->setWebhook (Number::WEBHOOK_MESSAGE , 'https://example.com/new_message ' );
108108 $ number ->setWebhook (Number::WEBHOOK_VOICE_STATUS , 'https://example.com/new_status ' );
109109 $ number ->setVoiceDestination ('https://example.com/new_voice ' );
110110
111- $ noLookup = new Number ('12404284163 ' , 'US ' );
111+ $ noLookup = new Number ('1415550100 ' , 'US ' );
112112 $ noLookup ->setWebhook (Number::WEBHOOK_MESSAGE , 'https://example.com/new_message ' );
113113 $ noLookup ->setWebhook (Number::WEBHOOK_VOICE_STATUS , 'https://example.com/new_status ' );
114114 $ noLookup ->setVoiceDestination ('https://example.com/new_voice ' );
115115
116- $ fresh = new Number ('12404284163 ' , 'US ' );
116+ $ fresh = new Number ('1415550100 ' , 'US ' );
117117 $ fresh ->setWebhook (Number::WEBHOOK_MESSAGE , 'https://example.com/new_message ' );
118118 $ fresh ->setWebhook (Number::WEBHOOK_VOICE_STATUS , 'https://example.com/new_status ' );
119119 $ fresh ->setVoiceDestination ('https://example.com/new_voice ' );
120120
121121 return [
122- [$ raw , '12404284163 ' , '12404284163 ' , true ],
123- [$ rawId , null , '12404284163 ' , false ],
124- [clone $ number , null , '12404284163 ' , true ],
125- [clone $ number , '14845551212 ' , '14845551212 ' , true ],
126- [clone $ noLookup , null , '12404284163 ' , false ],
127- [clone $ fresh , '12404284163 ' , '12404284163 ' , true ],
122+ [$ raw , '1415550100 ' , '1415550100 ' , true ],
123+ [$ rawId , null , '1415550100 ' , false ],
124+ [clone $ number , null , '1415550100 ' , true ],
125+ [clone $ number , '1415550100 ' , '1415550100 ' , true ],
126+ [clone $ noLookup , null , '1415550100 ' , false ],
127+ [clone $ fresh , '1415550100 ' , '1415550100 ' , true ],
128128 ];
129129 }
130130
@@ -154,8 +154,8 @@ public function testGetNumber($payload, $id)
154154 public function numbers ()
155155 {
156156 return [
157- ['12404284163 ' , '12404284163 ' ],
158- [new Number ('12404284163 ' ), '12404284163 ' ],
157+ ['1415550100 ' , '1415550100 ' ],
158+ [new Number ('1415550100 ' ), '1415550100 ' ],
159159 ];
160160 }
161161
@@ -249,11 +249,20 @@ public function testPurchaseNumberWithNumberObject()
249249
250250 public function testPurchaseNumberWithNumberAndCountry ()
251251 {
252+ // When providing a number string, the first thing that happens is a GET request to fetch number details
252253 $ this ->nexmoClient ->send (Argument::that (function (RequestInterface $ request ){
253- $ this ->assertEquals ('/number/buy ' , $ request ->getUri ()->getPath ());
254- $ this ->assertEquals ('rest.nexmo.com ' , $ request ->getUri ()->getHost ());
255- $ this ->assertEquals ('POST ' , $ request ->getMethod ());
256- return true ;
254+ return $ request ->getUri ()->getPath () === '/account/numbers ' ;
255+ }))->willReturn ($ this ->getResponse ('single ' ));
256+
257+ // Then we purchase the number
258+ $ this ->nexmoClient ->send (Argument::that (function (RequestInterface $ request ){
259+ if ($ request ->getUri ()->getPath () === '/number/buy ' ) {
260+ $ this ->assertEquals ('/number/buy ' , $ request ->getUri ()->getPath ());
261+ $ this ->assertEquals ('rest.nexmo.com ' , $ request ->getUri ()->getHost ());
262+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
263+ return true ;
264+ }
265+ return false ;
257266 }))->willReturn ($ this ->getResponse ('post ' ));
258267 $ this ->numberClient ->purchase ('1415550100 ' , 'US ' );
259268
@@ -276,7 +285,8 @@ public function testPurchaseNumberErrors($number, $country, $responseFile, $expe
276285 $ this ->expectException ($ expectedException );
277286 $ this ->expectExceptionMessage ($ expectedExceptionMessage );
278287
279- $ this ->numberClient ->purchase ($ number , $ country );
288+ $ num = new Number ($ number , $ country );
289+ $ this ->numberClient ->purchase ($ num );
280290 }
281291
282292 public function purchaseNumberErrorProvider ()
@@ -290,6 +300,62 @@ public function purchaseNumberErrorProvider()
290300 return $ r ;
291301 }
292302
303+ public function testCancelNumberWithNumberObject ()
304+ {
305+ $ this ->nexmoClient ->send (Argument::that (function (RequestInterface $ request ){
306+ $ this ->assertEquals ('/number/cancel ' , $ request ->getUri ()->getPath ());
307+ $ this ->assertEquals ('rest.nexmo.com ' , $ request ->getUri ()->getHost ());
308+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
309+ return true ;
310+ }))->willReturn ($ this ->getResponse ('cancel ' ));
311+
312+ $ number = new Number ('1415550100 ' , 'US ' );
313+ $ this ->numberClient ->cancel ($ number );
314+
315+ // There's nothing to assert here as we don't do anything with the response.
316+ // If there's no exception thrown, everything is fine!
317+ }
318+
319+ public function testCancelNumberWithNumberString ()
320+ {
321+
322+ // When providing a number string, the first thing that happens is a GET request to fetch number details
323+ $ this ->nexmoClient ->send (Argument::that (function (RequestInterface $ request ){
324+ return $ request ->getUri ()->getPath () === '/account/numbers ' ;
325+ }))->willReturn ($ this ->getResponse ('single ' ));
326+
327+
328+ // Then we get a POST request to cancel
329+ $ this ->nexmoClient ->send (Argument::that (function (RequestInterface $ request ) {
330+ if ($ request ->getUri ()->getPath () === '/number/cancel ' ) {
331+ $ this ->assertEquals ('rest.nexmo.com ' , $ request ->getUri ()->getHost ());
332+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
333+ return true ;
334+ }
335+ return false ;
336+ }))->willReturn ($ this ->getResponse ('cancel ' ));
337+
338+ $ this ->numberClient ->cancel ('1415550100 ' );
339+
340+ // There's nothing to assert here as we don't do anything with the response.
341+ // If there's no exception thrown, everything is fine!
342+ }
343+
344+ public function testCancelNumberError ()
345+ {
346+ $ this ->nexmoClient ->send (Argument::that (function (RequestInterface $ request ){
347+ $ this ->assertEquals ('/number/cancel ' , $ request ->getUri ()->getPath ());
348+ $ this ->assertEquals ('rest.nexmo.com ' , $ request ->getUri ()->getHost ());
349+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
350+ return true ;
351+ }))->willReturn ($ this ->getResponse ('method-failed ' , 420 ));
352+
353+ $ this ->expectException (Exception \Request::class);
354+ $ this ->expectExceptionMessage ('method failed ' );
355+
356+ $ num = new Number ('1415550100 ' , 'US ' );
357+ $ this ->numberClient ->cancel ($ num );
358+ }
293359
294360 /**
295361 * Get the API response we'd expect for a call to the API.
0 commit comments