Skip to content

Commit

Permalink
Refactor to only use one trait for responses, killed old dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Jul 24, 2024
1 parent 6e33d81 commit 89365d5
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 568 deletions.
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<testsuite name="default">
<directory>test</directory>
</testsuite>
<testsuite name="verify">
<directory>test/Verify</directory>
</testsuite>
<testsuite name="verify2">
<directory>test/Verify2</directory>
</testsuite>
Expand Down
39 changes: 14 additions & 25 deletions test/Account/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace VonageTest\Account;

use Laminas\Diactoros\Response;
use Prophecy\Argument;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\RequestInterface;
use VonageTest\Traits\Psr7AssertionTrait;
use Vonage\Account\Client as AccountClient;
use Vonage\Account\Network;
use Vonage\Account\PrefixPrice;
Expand All @@ -17,12 +15,14 @@
use Vonage\Client\Exception as ClientException;
use Vonage\Client\Exception\Request as RequestException;
use Vonage\Client\Exception\Server as ServerException;
use VonageTest\Traits\HTTPTestTrait;
use VonageTest\Traits\Psr7AssertionTrait;
use VonageTest\VonageTestCase;
use function fopen;

class ClientTest extends VonageTestCase
{
use Psr7AssertionTrait;
use HTTPTestTrait;

protected $vonageClient;

Expand All @@ -38,6 +38,8 @@ class ClientTest extends VonageTestCase

public function setUp(): void
{
$this->responsesDirectory = __DIR__ . '/responses';

$this->vonageClient = $this->prophesize(Client::class);
$this->vonageClient->getRestUrl()->willReturn('https://rest.nexmo.com');
$this->vonageClient->getApiUrl()->willReturn('https://api.nexmo.com');
Expand Down Expand Up @@ -154,7 +156,7 @@ public function testGetBalance(): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/account/get-balance', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);

$uri = $request->getUri();
$uriString = $uri->__toString();
Expand Down Expand Up @@ -184,7 +186,7 @@ public function testGetBalanceWithNoResults(): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/account/get-balance', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);

return true;
}))->shouldBeCalledTimes(1)->willReturn($this->getResponse('empty'));
Expand Down Expand Up @@ -313,7 +315,7 @@ public function testGetSmsPricing(): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/account/get-pricing/outbound/sms', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);
$this->assertRequestQueryContains('country', 'US', $request);

return true;
Expand All @@ -338,7 +340,7 @@ public function testGetSmsPricingReturnsEmptySet(): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/account/get-pricing/outbound/sms', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);
$this->assertRequestQueryContains('country', 'XX', $request);

return true;
Expand All @@ -358,7 +360,7 @@ public function testGetVoicePricing(): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/account/get-pricing/outbound/voice', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);
$this->assertRequestQueryContains('country', 'US', $request);

return true;
Expand All @@ -379,7 +381,7 @@ public function testGetPrefixPricing(): void

$this->assertEquals('/account/get-prefix-pricing/outbound', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);
$this->assertRequestQueryContains('prefix', '263', $request);

if ($hasRun) {
Expand All @@ -401,7 +403,7 @@ public function testGetPrefixPricingNoResults(): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/account/get-prefix-pricing/outbound', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);
$this->assertRequestQueryContains('prefix', '263', $request);

return true;
Expand All @@ -419,7 +421,7 @@ public function testGetPrefixPricingGenerates4xxError(): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/account/get-prefix-pricing/outbound', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);
$this->assertRequestQueryContains('prefix', '263', $request);

return true;
Expand All @@ -436,25 +438,12 @@ public function testGetPrefixPricingGenerates5xxError(): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
$this->assertEquals('/account/get-prefix-pricing/outbound', $request->getUri()->getPath());
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);
$this->assertRequestQueryContains('prefix', '263', $request);

return true;
}))->shouldBeCalledTimes(1)->willReturn($this->getResponse('prefix-pricing-server-failure', 500));

$this->accountClient->getPrefixPricing('263');
}

/**
* Get the API response we'd expect for a call to the API.
*/
protected function getResponse(string $type = 'success', int $status = 200): Response
{
return new Response(fopen(__DIR__ . '/responses/' . $type . '.json', 'rb'), $status);
}

protected function getGenericResponse(string $type = 'success', int $status = 200): Response
{
return new Response(fopen(__DIR__ . '/../responses/general/' . $type . '.json', 'rb'), $status);
}
}
18 changes: 6 additions & 12 deletions test/Application/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
namespace VonageTest\Application;

use Exception;
use Laminas\Diactoros\Response;
use VonageTest\VonageTestCase;
use Vonage\Application\Application;
use Vonage\Application\MessagesConfig;
use Vonage\Application\RtcConfig;
use Vonage\Application\VoiceConfig;
use Vonage\Client\Exception\Exception as ClientException;

use function fopen;
use VonageTest\Traits\HTTPTestTrait;
use VonageTest\VonageTestCase;

class ApplicationTest extends VonageTestCase
{
use HTTPTestTrait;

/**
* @var Application
*/
protected $app;

public function setUp(): void
{
$this->responsesDirectory = __DIR__ . '/responses';

$this->app = (new Application())->setName('test');
}

Expand Down Expand Up @@ -162,12 +164,4 @@ public function testConfigCanBeCopied(): void
$webhook = $otherapp->getVoiceConfig()->getWebhook(VoiceConfig::ANSWER);
$this->assertEquals('https://example.com/webhooks/answer', $webhook);
}

/**
* Get the API response we'd expect for a call to the API.
*/
protected function getResponse(string $type = 'success'): Response
{
return new Response(fopen(__DIR__ . '/responses/' . $type . '.json', 'rb'));
}
}
17 changes: 6 additions & 11 deletions test/Application/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Prophecy\Argument;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\RequestInterface;
use VonageTest\Traits\Psr7AssertionTrait;
use Vonage\Application\Application;
use Vonage\Application\Client as ApplicationClient;
use Vonage\Application\Hydrator;
Expand All @@ -23,14 +22,16 @@
use Vonage\Client\APIResource;
use Vonage\Client\Exception\Exception as ClientException;
use Vonage\Client\Exception\Server as ServerException;
use VonageTest\Traits\HTTPTestTrait;
use VonageTest\Traits\Psr7AssertionTrait;
use VonageTest\VonageTestCase;
use function fopen;
use function json_decode;
use function substr;

class ClientTest extends VonageTestCase
{
use Psr7AssertionTrait;
use HTTPTestTrait;

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

Expand All @@ -46,6 +47,8 @@ class ClientTest extends VonageTestCase

public function setUp(): void
{
$this->responsesDirectory = __DIR__ . '/responses/';

$this->vonageClient = $this->prophesize(Client::class);
$this->vonageClient->getApiUrl()->willReturn('https://api.nexmo.com');
$this->vonageClient->getCredentials()->willReturn(
Expand Down Expand Up @@ -88,7 +91,7 @@ public function testGetApplication($payload, $id, $expectsError): void
$this->vonageClient->send(Argument::that(function (RequestInterface $request) use ($id) {
$this->assertEquals('/v2/applications/' . $id, $request->getUri()->getPath());
$this->assertEquals('api.nexmo.com', $request->getUri()->getHost());
$this->assertRequestMethod('GET', $request);
$this->assertRequestMethod('GET', $request);
return true;
}))->willReturn($this->getResponse());

Expand Down Expand Up @@ -552,12 +555,4 @@ public function testCannotSetUnknownRegion(): void
$application->setName('my application');
$application->getVoiceConfig()->setRegion('eu-west-1');
}

/**
* Get the API response we'd expect for a call to the API.
*/
protected function getResponse(string $type = 'success', int $status = 200): Response
{
return new Response(fopen(__DIR__ . '/responses/' . $type . '.json', 'rb'), $status);
}
}
2 changes: 1 addition & 1 deletion test/Client/Credentials/Handler/GnpHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Vonage\Client\Credentials\Gnp;
use PHPUnit\Framework\TestCase;
use Vonage\Client\Credentials\Handler\SimSwapGnpHandler;
use VonageTest\Psr7AssertionTrait;
use VonageTest\Traits\Psr7AssertionTrait;

class GnpHandlerTest extends TestCase
{
Expand Down
12 changes: 5 additions & 7 deletions test/Conversation/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace VonageTest\Conversation;

use Laminas\Diactoros\Request;
use Laminas\Diactoros\Response;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use VonageTest\Traits\Psr7AssertionTrait;
use Vonage\Client;
use Vonage\Client\APIResource;
use Vonage\Conversation\Client as ConversationClient;
Expand All @@ -27,11 +25,14 @@
use Vonage\Conversation\Filter\ListMembersFilter;
use Vonage\Conversation\Filter\ListUserConversationsFilter;
use Vonage\Entity\IterableAPICollection;
use VonageTest\Traits\HTTPTestTrait;
use VonageTest\Traits\Psr7AssertionTrait;
use VonageTest\VonageTestCase;

class ClientTest extends VonageTestCase
{
use Psr7AssertionTrait;
use HTTPTestTrait;

protected ObjectProphecy $vonageClient;
protected ConversationClient $conversationsClient;
Expand All @@ -40,6 +41,8 @@ class ClientTest extends VonageTestCase

public function setUp(): void
{
$this->responsesDirectory = __DIR__ . '/Fixtures/Responses';

$this->vonageClient = $this->prophesize(Client::class);
$this->vonageClient->getRestUrl()->willReturn('https://api.nexmo.com');
$this->vonageClient->getCredentials()->willReturn(
Expand Down Expand Up @@ -795,9 +798,4 @@ public function testWillDeleteEvent(): void

$this->assertTrue($response);
}

protected function getResponse(string $identifier, int $status = 200): Response
{
return new Response(fopen(__DIR__ . '/Fixtures/Responses/' . $identifier . '.json', 'rb'), $status);
}
}
16 changes: 5 additions & 11 deletions test/Conversion/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

namespace VonageTest\Conversion;

use Laminas\Diactoros\Response;
use PHPUnit\Framework\MockObject\MockObject;
use Prophecy\Argument;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\RequestInterface;
use VonageTest\Traits\Psr7AssertionTrait;
use Vonage\Client;
use Vonage\Client as VonageClient;
use Vonage\Client\APIResource;
use Vonage\Client\Exception\Exception as ClientException;
use Vonage\Client\Exception\Request as RequestException;
use Vonage\Client\Exception\Server as ServerException;
use Vonage\Conversion\Client as ConversionClient;
use VonageTest\Traits\HTTPTestTrait;
use VonageTest\Traits\Psr7AssertionTrait;
use VonageTest\VonageTestCase;
use function fopen;

class ClientTest extends VonageTestCase
{
use Psr7AssertionTrait;
use HTTPTestTrait;

/**
* @var Client|MockObject
Expand All @@ -43,6 +43,8 @@ class ClientTest extends VonageTestCase

public function setUp(): void
{
$this->responsesDirectory = 'data://text/plain,';

$this->vonageClient = $this->prophesize(VonageClient::class);
$this->vonageClient->getRestUrl()->willReturn('https://rest.nexmo.com');
$this->vonageClient->getApiUrl()->willReturn('https://api.nexmo.com');
Expand Down Expand Up @@ -135,12 +137,4 @@ public function testVoiceWithoutTimestamp(): void

$this->conversionClient->voice('ABC123', true);
}

/**
* Get the API response we'd expect for a call to the API.
*/
protected function getResponse(): Response
{
return new Response(fopen('data://text/plain,', 'rb'), 200);
}
}
15 changes: 0 additions & 15 deletions test/FixedVersionClient.php

This file was deleted.

Loading

0 comments on commit 89365d5

Please sign in to comment.