Skip to content

Commit

Permalink
small bits from reviewing numbers API (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK authored Aug 20, 2024
1 parent 4d9540e commit 1167fa4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 153 deletions.
28 changes: 0 additions & 28 deletions src/Numbers/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public function getApiResource(): APIResource
}

/**
* @param Number $number
* @param string|null $id
*
* @return Number
* @throws ClientExceptionInterface
* @throws Exception
* @throws Request
Expand Down Expand Up @@ -84,11 +80,8 @@ public function update(Number $number, ?string $id = null): Number
}

/**
* Returns a number
*
* @param string $number Number to fetch, deprecating passing a `Number` object
*
* @return Number
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Request
Expand All @@ -108,12 +101,6 @@ public function get(string $number): Number
}

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

/**
* Returns a set of numbers for the specified country
*
* @param null $number
* @param FilterInterface|null $options
*
* @return array
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Request
Expand Down Expand Up @@ -176,8 +157,6 @@ public function searchOwned($number = null, FilterInterface $options = null): ar
}

/**
* @param $number deprecated
*
* @throws ClientException\Exception
* @throws ClientException\Request
* @throws ClientException\Server
Expand All @@ -203,8 +182,6 @@ private function handleNumberSearchResult(IterableAPICollection $response, $numb
}

/**
* @param $number
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
*/
Expand All @@ -217,7 +194,6 @@ public function purchase($number, ?string $country = null): void
}

if ($number instanceof Number) {

trigger_error(
'Passing a Number object to Vonage\Number\Client::purchase() is being deprecated, ' .
'please pass a string MSISDN instead',
Expand All @@ -230,7 +206,6 @@ public function purchase($number, ?string $country = null): void
];
// Evil else that will be removed in the next major version.
} else {

$body = [
'msisdn' => $number,
'country' => $country
Expand All @@ -243,9 +218,6 @@ public function purchase($number, ?string $country = null): void
}

/**
* @param string $number
* @param string|null $country
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Request
Expand Down
134 changes: 9 additions & 125 deletions test/Numbers/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use VonageTest\Traits\HTTPTestTrait;
use VonageTest\Traits\Psr7AssertionTrait;
use VonageTest\VonageTestCase;

use function is_null;

class ClientTest extends VonageTestCase
Expand All @@ -31,13 +32,10 @@ class ClientTest extends VonageTestCase
*/
protected APIResource $apiClient;

protected $vonageClient;
protected \Vonage\Client|\Prophecy\Prophecy\ObjectProphecy $vonageClient;

protected APIResource $api;

/**
* @var NumbersClient
*/
protected NumbersClient $numberClient;

public function setUp(): void
Expand All @@ -62,15 +60,6 @@ public function setUp(): void

/**
* @dataProvider updateNumber
*
* @param $payload
* @param $id
* @param $expectedId
* @param $lookup
*
* @throws ClientException\Exception
* @throws RequestException
* @throws ClientExceptionInterface
*/
public function testUpdateNumber($payload, $id, $expectedId, $lookup): void
{
Expand Down Expand Up @@ -123,9 +112,6 @@ public function testUpdateNumber($payload, $id, $expectedId, $lookup): void
}
}

/**
* @return array[]
*/
public function updateNumber(): array
{
$number = new Number('1415550100');
Expand All @@ -144,23 +130,12 @@ public function updateNumber(): array
$fresh->setVoiceDestination('https://example.com/new_voice');

return [
// [clone $number, null, '1415550100', true],
[clone $number, '1415550100', '1415550100', true],
// [clone $noLookup, null, '1415550100', false],
// [clone $fresh, '1415550100', '1415550100', true],
];
}

/**
* @dataProvider numbers
*
* @param $payload
* @param $id
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testGetNumber($payload, $id): void
{
Expand Down Expand Up @@ -188,12 +163,6 @@ public function numbers(): array
];
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testListNumbers(): void
{
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
Expand All @@ -212,12 +181,6 @@ public function testListNumbers(): void
$this->assertSame('14155550101', $numbers[1]->getId());
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testSearchAvailablePassesThroughWhitelistedOptions(): void
{
$options = [
Expand All @@ -244,41 +207,29 @@ public function testSearchAvailablePassesThroughWhitelistedOptions(): void
$this->numberClient->searchAvailable('US', new AvailableNumbers($options));
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testSearchAvailableAcceptsFilterInterfaceOptions(): void
{
$options = new AvailableNumbers([
'pattern' => '1',
'search_pattern' => 2,
'type' => 'landline',
'features' => 'SMS,VOICE',
'size' => '100',
'index' => '19'
]);

$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/number/search', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$uri = $request->getUri();
$uriString = $uri->__toString();
$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);
$this->assertRequestMethod('GET', $request);

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

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

/**
* Make sure that unknown parameters fail validation
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testUnknownParameterValueForSearchThrowsException(): void
{
$this->expectException(RequestException::class);
Expand All @@ -287,12 +238,6 @@ public function testUnknownParameterValueForSearchThrowsException(): void
$this->numberClient->searchAvailable('US', new AvailableNumbers(['foo' => 'bar']));
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testSearchAvailableReturnsNumberList(): void
{
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
Expand All @@ -314,11 +259,6 @@ public function testSearchAvailableReturnsNumberList(): void

/**
* A search can return an empty set `[]` result when no numbers are found
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testSearchAvailableReturnsEmptyNumberList(): void
{
Expand All @@ -336,12 +276,6 @@ public function testSearchAvailableReturnsEmptyNumberList(): void
$this->assertEmpty($numbers);
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testSearchOwnedErrorsOnUnknownSearchParameters(): void
{
$this->expectException(ClientException\Request::class);
Expand All @@ -350,12 +284,6 @@ public function testSearchOwnedErrorsOnUnknownSearchParameters(): void
$this->numberClient->searchOwned(new OwnedNumbers(['foo' => 'bar']), '1415550100');
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testSearchOwnedPassesInAllowedAdditionalParameters(): void
{
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
Expand Down Expand Up @@ -383,12 +311,6 @@ public function testSearchOwnedPassesInAllowedAdditionalParameters(): void
);
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testSearchOwnedReturnsSingleNumber(): void
{
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
Expand All @@ -406,15 +328,13 @@ public function testSearchOwnedReturnsSingleNumber(): void
$this->assertSame('1415550100', $numbers[0]->getId());
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
*/
public function testPurchaseNumberWithNumberObject(): void
{
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/number/buy', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestFormBodyContains('country', 'US', $request);
$this->assertRequestFormBodyContains('msisdn', '1415550100', $request);
$this->assertEquals('POST', $request->getMethod());

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

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
*/
public function testPurchaseNumberWithNumberAndCountry(): void
{
// When providing a number string, the first thing that happens is a GET request to fetch number details
Expand All @@ -453,16 +369,6 @@ public function testPurchaseNumberWithNumberAndCountry(): void

/**
* @dataProvider purchaseNumberErrorProvider
*
* @param $number
* @param $country
* @param $responseFile
* @param $expectedHttpCode
* @param $expectedException
* @param $expectedExceptionMessage
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
*/
public function testPurchaseNumberErrors(
$number,
Expand Down Expand Up @@ -519,12 +425,6 @@ public function purchaseNumberErrorProvider(): array
return $r;
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testCancelNumberWithNumberString(): void
{
// When providing a number string, the first thing that happens is a GET request to fetch number details
Expand All @@ -544,12 +444,6 @@ public function testCancelNumberWithNumberString(): void
@$this->numberClient->cancel('1415550100');
}

/**
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testCancelNumberWithNumberAndCountryString(): void
{
// When providing a number string, the first thing that happens is a GET request to fetch number details
Expand All @@ -571,11 +465,6 @@ public function testCancelNumberWithNumberAndCountryString(): void

/**
* Make sure that integer values that fail validation throw properly
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testInvalidIntegerValueForSearchThrowsException(): void
{
Expand All @@ -587,11 +476,6 @@ public function testInvalidIntegerValueForSearchThrowsException(): void

/**
* Make sure that boolean values that fail validation throw properly
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Server
* @throws RequestException
*/
public function testInvalidBooleanValueForSearchThrowsException(): void
{
Expand Down

0 comments on commit 1167fa4

Please sign in to comment.