Skip to content

Commit 1167fa4

Browse files
authored
small bits from reviewing numbers API (#498)
1 parent 4d9540e commit 1167fa4

File tree

2 files changed

+9
-153
lines changed

2 files changed

+9
-153
lines changed

src/Numbers/Client.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public function getApiResource(): APIResource
3434
}
3535

3636
/**
37-
* @param Number $number
38-
* @param string|null $id
39-
*
40-
* @return Number
4137
* @throws ClientExceptionInterface
4238
* @throws Exception
4339
* @throws Request
@@ -84,11 +80,8 @@ public function update(Number $number, ?string $id = null): Number
8480
}
8581

8682
/**
87-
* Returns a number
88-
*
8983
* @param string $number Number to fetch, deprecating passing a `Number` object
9084
*
91-
* @return Number
9285
* @throws ClientExceptionInterface
9386
* @throws ClientException\Exception
9487
* @throws ClientException\Request
@@ -108,12 +101,6 @@ public function get(string $number): Number
108101
}
109102

110103
/**
111-
* Returns a set of numbers for the specified country
112-
*
113-
* @param string $country The two character country code in ISO 3166-1 alpha-2 format
114-
* @param FilterInterface $options Additional options, see https://developer.nexmo.com/api/numbers#getAvailableNumbers
115-
*
116-
* @return array
117104
* @throws ClientExceptionInterface
118105
* @throws ClientException\Exception
119106
* @throws ClientException\Request
@@ -142,12 +129,6 @@ public function searchAvailable(string $country, FilterInterface $options = null
142129
}
143130

144131
/**
145-
* Returns a set of numbers for the specified country
146-
*
147-
* @param null $number
148-
* @param FilterInterface|null $options
149-
*
150-
* @return array
151132
* @throws ClientExceptionInterface
152133
* @throws ClientException\Exception
153134
* @throws ClientException\Request
@@ -176,8 +157,6 @@ public function searchOwned($number = null, FilterInterface $options = null): ar
176157
}
177158

178159
/**
179-
* @param $number deprecated
180-
*
181160
* @throws ClientException\Exception
182161
* @throws ClientException\Request
183162
* @throws ClientException\Server
@@ -203,8 +182,6 @@ private function handleNumberSearchResult(IterableAPICollection $response, $numb
203182
}
204183

205184
/**
206-
* @param $number
207-
*
208185
* @throws ClientExceptionInterface
209186
* @throws ClientException\Exception
210187
*/
@@ -217,7 +194,6 @@ public function purchase($number, ?string $country = null): void
217194
}
218195

219196
if ($number instanceof Number) {
220-
221197
trigger_error(
222198
'Passing a Number object to Vonage\Number\Client::purchase() is being deprecated, ' .
223199
'please pass a string MSISDN instead',
@@ -230,7 +206,6 @@ public function purchase($number, ?string $country = null): void
230206
];
231207
// Evil else that will be removed in the next major version.
232208
} else {
233-
234209
$body = [
235210
'msisdn' => $number,
236211
'country' => $country
@@ -243,9 +218,6 @@ public function purchase($number, ?string $country = null): void
243218
}
244219

245220
/**
246-
* @param string $number
247-
* @param string|null $country
248-
*
249221
* @throws ClientExceptionInterface
250222
* @throws ClientException\Exception
251223
* @throws ClientException\Request

test/Numbers/ClientTest.php

Lines changed: 9 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use VonageTest\Traits\HTTPTestTrait;
2020
use VonageTest\Traits\Psr7AssertionTrait;
2121
use VonageTest\VonageTestCase;
22+
2223
use function is_null;
2324

2425
class ClientTest extends VonageTestCase
@@ -31,13 +32,10 @@ class ClientTest extends VonageTestCase
3132
*/
3233
protected APIResource $apiClient;
3334

34-
protected $vonageClient;
35+
protected \Vonage\Client|\Prophecy\Prophecy\ObjectProphecy $vonageClient;
3536

3637
protected APIResource $api;
3738

38-
/**
39-
* @var NumbersClient
40-
*/
4139
protected NumbersClient $numberClient;
4240

4341
public function setUp(): void
@@ -62,15 +60,6 @@ public function setUp(): void
6260

6361
/**
6462
* @dataProvider updateNumber
65-
*
66-
* @param $payload
67-
* @param $id
68-
* @param $expectedId
69-
* @param $lookup
70-
*
71-
* @throws ClientException\Exception
72-
* @throws RequestException
73-
* @throws ClientExceptionInterface
7463
*/
7564
public function testUpdateNumber($payload, $id, $expectedId, $lookup): void
7665
{
@@ -123,9 +112,6 @@ public function testUpdateNumber($payload, $id, $expectedId, $lookup): void
123112
}
124113
}
125114

126-
/**
127-
* @return array[]
128-
*/
129115
public function updateNumber(): array
130116
{
131117
$number = new Number('1415550100');
@@ -144,23 +130,12 @@ public function updateNumber(): array
144130
$fresh->setVoiceDestination('https://example.com/new_voice');
145131

146132
return [
147-
// [clone $number, null, '1415550100', true],
148133
[clone $number, '1415550100', '1415550100', true],
149-
// [clone $noLookup, null, '1415550100', false],
150-
// [clone $fresh, '1415550100', '1415550100', true],
151134
];
152135
}
153136

154137
/**
155138
* @dataProvider numbers
156-
*
157-
* @param $payload
158-
* @param $id
159-
*
160-
* @throws ClientExceptionInterface
161-
* @throws ClientException\Exception
162-
* @throws ClientException\Server
163-
* @throws RequestException
164139
*/
165140
public function testGetNumber($payload, $id): void
166141
{
@@ -188,12 +163,6 @@ public function numbers(): array
188163
];
189164
}
190165

191-
/**
192-
* @throws ClientExceptionInterface
193-
* @throws ClientException\Exception
194-
* @throws ClientException\Server
195-
* @throws RequestException
196-
*/
197166
public function testListNumbers(): void
198167
{
199168
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
@@ -212,12 +181,6 @@ public function testListNumbers(): void
212181
$this->assertSame('14155550101', $numbers[1]->getId());
213182
}
214183

215-
/**
216-
* @throws ClientExceptionInterface
217-
* @throws ClientException\Exception
218-
* @throws ClientException\Server
219-
* @throws RequestException
220-
*/
221184
public function testSearchAvailablePassesThroughWhitelistedOptions(): void
222185
{
223186
$options = [
@@ -244,41 +207,29 @@ public function testSearchAvailablePassesThroughWhitelistedOptions(): void
244207
$this->numberClient->searchAvailable('US', new AvailableNumbers($options));
245208
}
246209

247-
/**
248-
* @throws ClientExceptionInterface
249-
* @throws ClientException\Exception
250-
* @throws ClientException\Server
251-
* @throws RequestException
252-
*/
253210
public function testSearchAvailableAcceptsFilterInterfaceOptions(): void
254211
{
255212
$options = new AvailableNumbers([
256213
'pattern' => '1',
257214
'search_pattern' => 2,
215+
'type' => 'landline',
258216
'features' => 'SMS,VOICE',
259217
'size' => '100',
260218
'index' => '19'
261219
]);
262220

263221
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
264-
$this->assertEquals('/number/search', $request->getUri()->getPath());
265-
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
266-
$this->assertRequestMethod('GET', $request);
222+
$uri = $request->getUri();
223+
$uriString = $uri->__toString();
224+
$this->assertEquals('https://rest.nexmo.com/number/search?size=100&index=19&country=US&search_pattern=2&pattern=1&type=landline&features=SMS%2CVOICE&page_index=1', $uriString);
225+
$this->assertRequestMethod('GET', $request);
267226

268227
return true;
269228
}))->willReturn($this->getResponse('available-numbers'));
270229

271230
$this->numberClient->searchAvailable('US', $options);
272231
}
273232

274-
/**
275-
* Make sure that unknown parameters fail validation
276-
*
277-
* @throws ClientExceptionInterface
278-
* @throws ClientException\Exception
279-
* @throws ClientException\Server
280-
* @throws RequestException
281-
*/
282233
public function testUnknownParameterValueForSearchThrowsException(): void
283234
{
284235
$this->expectException(RequestException::class);
@@ -287,12 +238,6 @@ public function testUnknownParameterValueForSearchThrowsException(): void
287238
$this->numberClient->searchAvailable('US', new AvailableNumbers(['foo' => 'bar']));
288239
}
289240

290-
/**
291-
* @throws ClientExceptionInterface
292-
* @throws ClientException\Exception
293-
* @throws ClientException\Server
294-
* @throws RequestException
295-
*/
296241
public function testSearchAvailableReturnsNumberList(): void
297242
{
298243
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
@@ -314,11 +259,6 @@ public function testSearchAvailableReturnsNumberList(): void
314259

315260
/**
316261
* A search can return an empty set `[]` result when no numbers are found
317-
*
318-
* @throws ClientExceptionInterface
319-
* @throws ClientException\Exception
320-
* @throws ClientException\Server
321-
* @throws RequestException
322262
*/
323263
public function testSearchAvailableReturnsEmptyNumberList(): void
324264
{
@@ -336,12 +276,6 @@ public function testSearchAvailableReturnsEmptyNumberList(): void
336276
$this->assertEmpty($numbers);
337277
}
338278

339-
/**
340-
* @throws ClientExceptionInterface
341-
* @throws ClientException\Exception
342-
* @throws ClientException\Server
343-
* @throws RequestException
344-
*/
345279
public function testSearchOwnedErrorsOnUnknownSearchParameters(): void
346280
{
347281
$this->expectException(ClientException\Request::class);
@@ -350,12 +284,6 @@ public function testSearchOwnedErrorsOnUnknownSearchParameters(): void
350284
$this->numberClient->searchOwned(new OwnedNumbers(['foo' => 'bar']), '1415550100');
351285
}
352286

353-
/**
354-
* @throws ClientExceptionInterface
355-
* @throws ClientException\Exception
356-
* @throws ClientException\Server
357-
* @throws RequestException
358-
*/
359287
public function testSearchOwnedPassesInAllowedAdditionalParameters(): void
360288
{
361289
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
@@ -383,12 +311,6 @@ public function testSearchOwnedPassesInAllowedAdditionalParameters(): void
383311
);
384312
}
385313

386-
/**
387-
* @throws ClientExceptionInterface
388-
* @throws ClientException\Exception
389-
* @throws ClientException\Server
390-
* @throws RequestException
391-
*/
392314
public function testSearchOwnedReturnsSingleNumber(): void
393315
{
394316
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
@@ -406,15 +328,13 @@ public function testSearchOwnedReturnsSingleNumber(): void
406328
$this->assertSame('1415550100', $numbers[0]->getId());
407329
}
408330

409-
/**
410-
* @throws ClientExceptionInterface
411-
* @throws ClientException\Exception
412-
*/
413331
public function testPurchaseNumberWithNumberObject(): void
414332
{
415333
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
416334
$this->assertEquals('/number/buy', $request->getUri()->getPath());
417335
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
336+
$this->assertRequestFormBodyContains('country', 'US', $request);
337+
$this->assertRequestFormBodyContains('msisdn', '1415550100', $request);
418338
$this->assertEquals('POST', $request->getMethod());
419339

420340
return true;
@@ -425,10 +345,6 @@ public function testPurchaseNumberWithNumberObject(): void
425345
// If there's no exception thrown, everything is fine!
426346
}
427347

428-
/**
429-
* @throws ClientExceptionInterface
430-
* @throws ClientException\Exception
431-
*/
432348
public function testPurchaseNumberWithNumberAndCountry(): void
433349
{
434350
// When providing a number string, the first thing that happens is a GET request to fetch number details
@@ -453,16 +369,6 @@ public function testPurchaseNumberWithNumberAndCountry(): void
453369

454370
/**
455371
* @dataProvider purchaseNumberErrorProvider
456-
*
457-
* @param $number
458-
* @param $country
459-
* @param $responseFile
460-
* @param $expectedHttpCode
461-
* @param $expectedException
462-
* @param $expectedExceptionMessage
463-
*
464-
* @throws ClientExceptionInterface
465-
* @throws ClientException\Exception
466372
*/
467373
public function testPurchaseNumberErrors(
468374
$number,
@@ -519,12 +425,6 @@ public function purchaseNumberErrorProvider(): array
519425
return $r;
520426
}
521427

522-
/**
523-
* @throws ClientExceptionInterface
524-
* @throws ClientException\Exception
525-
* @throws ClientException\Server
526-
* @throws RequestException
527-
*/
528428
public function testCancelNumberWithNumberString(): void
529429
{
530430
// When providing a number string, the first thing that happens is a GET request to fetch number details
@@ -544,12 +444,6 @@ public function testCancelNumberWithNumberString(): void
544444
@$this->numberClient->cancel('1415550100');
545445
}
546446

547-
/**
548-
* @throws ClientExceptionInterface
549-
* @throws ClientException\Exception
550-
* @throws ClientException\Server
551-
* @throws RequestException
552-
*/
553447
public function testCancelNumberWithNumberAndCountryString(): void
554448
{
555449
// When providing a number string, the first thing that happens is a GET request to fetch number details
@@ -571,11 +465,6 @@ public function testCancelNumberWithNumberAndCountryString(): void
571465

572466
/**
573467
* Make sure that integer values that fail validation throw properly
574-
*
575-
* @throws ClientExceptionInterface
576-
* @throws ClientException\Exception
577-
* @throws ClientException\Server
578-
* @throws RequestException
579468
*/
580469
public function testInvalidIntegerValueForSearchThrowsException(): void
581470
{
@@ -587,11 +476,6 @@ public function testInvalidIntegerValueForSearchThrowsException(): void
587476

588477
/**
589478
* Make sure that boolean values that fail validation throw properly
590-
*
591-
* @throws ClientExceptionInterface
592-
* @throws ClientException\Exception
593-
* @throws ClientException\Server
594-
* @throws RequestException
595479
*/
596480
public function testInvalidBooleanValueForSearchThrowsException(): void
597481
{

0 commit comments

Comments
 (0)