Skip to content

Commit a241b67

Browse files
Converts $options to array if parameter it's a FilterInterface instance on Vonage\Numbers\Client::searchAvailable() (#255)
* When options parameter on Vonage\Numbers\Client::searchAvailable() is an instance of FilterInterface, it converts to array * Added unit test
1 parent 82d172e commit a241b67

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Numbers/Client.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ public function searchAvailable($country, $options = []) : array
193193
'index' => 'integer'
194194
];
195195

196+
if ($options instanceof FilterInterface) {
197+
$options = $options->getQuery();
198+
}
199+
196200
$options = $this->parseParameters($possibleParameters, $options);
197201
$options = new AvailableNumbers($options);
198202
$api = $this->getApiResource();

test/Numbers/ClientTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use VonageTest\Psr7AssertionTrait;
1919
use Vonage\Client\Exception\Request;
2020
use Psr\Http\Message\RequestInterface;
21+
use Vonage\Numbers\Filter\AvailableNumbers;
2122

2223
class ClientTest extends TestCase
2324
{
@@ -213,6 +214,26 @@ public function testSearchAvailablePassesThroughWhitelistedOptions()
213214
@$this->numberClient->searchAvailable('US', $options);
214215
}
215216

217+
public function testSearchAvailableAcceptsFilterInterfaceOptions()
218+
{
219+
$options = new AvailableNumbers([
220+
'pattern' => '1',
221+
'search_pattern' => 2,
222+
'features' => 'SMS,VOICE',
223+
'size' => 100,
224+
'index' => 19
225+
]);
226+
227+
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
228+
$this->assertEquals('/number/search', $request->getUri()->getPath());
229+
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
230+
$this->assertEquals('GET', $request->getMethod());
231+
return true;
232+
}))->willReturn($this->getResponse('available-numbers'));
233+
234+
@$this->numberClient->searchAvailable('US', $options);
235+
}
236+
216237
/**
217238
* Make sure that unknown parameters fail validation
218239
*/

0 commit comments

Comments
 (0)