Skip to content

Commit 89365d5

Browse files
committed
Refactor to only use one trait for responses, killed old dead code
1 parent 6e33d81 commit 89365d5

31 files changed

+144
-568
lines changed

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
<testsuite name="default">
2121
<directory>test</directory>
2222
</testsuite>
23+
<testsuite name="verify">
24+
<directory>test/Verify</directory>
25+
</testsuite>
2326
<testsuite name="verify2">
2427
<directory>test/Verify2</directory>
2528
</testsuite>

test/Account/ClientTest.php

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace VonageTest\Account;
66

7-
use Laminas\Diactoros\Response;
87
use Prophecy\Argument;
98
use Psr\Http\Client\ClientExceptionInterface;
109
use Psr\Http\Message\RequestInterface;
11-
use VonageTest\Traits\Psr7AssertionTrait;
1210
use Vonage\Account\Client as AccountClient;
1311
use Vonage\Account\Network;
1412
use Vonage\Account\PrefixPrice;
@@ -17,12 +15,14 @@
1715
use Vonage\Client\Exception as ClientException;
1816
use Vonage\Client\Exception\Request as RequestException;
1917
use Vonage\Client\Exception\Server as ServerException;
18+
use VonageTest\Traits\HTTPTestTrait;
19+
use VonageTest\Traits\Psr7AssertionTrait;
2020
use VonageTest\VonageTestCase;
21-
use function fopen;
2221

2322
class ClientTest extends VonageTestCase
2423
{
2524
use Psr7AssertionTrait;
25+
use HTTPTestTrait;
2626

2727
protected $vonageClient;
2828

@@ -38,6 +38,8 @@ class ClientTest extends VonageTestCase
3838

3939
public function setUp(): void
4040
{
41+
$this->responsesDirectory = __DIR__ . '/responses';
42+
4143
$this->vonageClient = $this->prophesize(Client::class);
4244
$this->vonageClient->getRestUrl()->willReturn('https://rest.nexmo.com');
4345
$this->vonageClient->getApiUrl()->willReturn('https://api.nexmo.com');
@@ -154,7 +156,7 @@ public function testGetBalance(): void
154156
$this->vonageClient->send(Argument::that(function (RequestInterface $request) {
155157
$this->assertEquals('/account/get-balance', $request->getUri()->getPath());
156158
$this->assertEquals('rest.nexmo.com', $request->getUri()->getHost());
157-
$this->assertRequestMethod('GET', $request);
159+
$this->assertRequestMethod('GET', $request);
158160

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

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

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

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

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

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

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

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

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

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

445447
$this->accountClient->getPrefixPricing('263');
446448
}
447-
448-
/**
449-
* Get the API response we'd expect for a call to the API.
450-
*/
451-
protected function getResponse(string $type = 'success', int $status = 200): Response
452-
{
453-
return new Response(fopen(__DIR__ . '/responses/' . $type . '.json', 'rb'), $status);
454-
}
455-
456-
protected function getGenericResponse(string $type = 'success', int $status = 200): Response
457-
{
458-
return new Response(fopen(__DIR__ . '/../responses/general/' . $type . '.json', 'rb'), $status);
459-
}
460449
}

test/Application/ApplicationTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55
namespace VonageTest\Application;
66

77
use Exception;
8-
use Laminas\Diactoros\Response;
9-
use VonageTest\VonageTestCase;
108
use Vonage\Application\Application;
119
use Vonage\Application\MessagesConfig;
1210
use Vonage\Application\RtcConfig;
1311
use Vonage\Application\VoiceConfig;
1412
use Vonage\Client\Exception\Exception as ClientException;
15-
16-
use function fopen;
13+
use VonageTest\Traits\HTTPTestTrait;
14+
use VonageTest\VonageTestCase;
1715

1816
class ApplicationTest extends VonageTestCase
1917
{
18+
use HTTPTestTrait;
19+
2020
/**
2121
* @var Application
2222
*/
2323
protected $app;
2424

2525
public function setUp(): void
2626
{
27+
$this->responsesDirectory = __DIR__ . '/responses';
28+
2729
$this->app = (new Application())->setName('test');
2830
}
2931

@@ -162,12 +164,4 @@ public function testConfigCanBeCopied(): void
162164
$webhook = $otherapp->getVoiceConfig()->getWebhook(VoiceConfig::ANSWER);
163165
$this->assertEquals('https://example.com/webhooks/answer', $webhook);
164166
}
165-
166-
/**
167-
* Get the API response we'd expect for a call to the API.
168-
*/
169-
protected function getResponse(string $type = 'success'): Response
170-
{
171-
return new Response(fopen(__DIR__ . '/responses/' . $type . '.json', 'rb'));
172-
}
173167
}

test/Application/ClientTest.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Prophecy\Argument;
1111
use Psr\Http\Client\ClientExceptionInterface;
1212
use Psr\Http\Message\RequestInterface;
13-
use VonageTest\Traits\Psr7AssertionTrait;
1413
use Vonage\Application\Application;
1514
use Vonage\Application\Client as ApplicationClient;
1615
use Vonage\Application\Hydrator;
@@ -23,14 +22,16 @@
2322
use Vonage\Client\APIResource;
2423
use Vonage\Client\Exception\Exception as ClientException;
2524
use Vonage\Client\Exception\Server as ServerException;
25+
use VonageTest\Traits\HTTPTestTrait;
26+
use VonageTest\Traits\Psr7AssertionTrait;
2627
use VonageTest\VonageTestCase;
27-
use function fopen;
2828
use function json_decode;
2929
use function substr;
3030

3131
class ClientTest extends VonageTestCase
3232
{
3333
use Psr7AssertionTrait;
34+
use HTTPTestTrait;
3435

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

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

4748
public function setUp(): void
4849
{
50+
$this->responsesDirectory = __DIR__ . '/responses/';
51+
4952
$this->vonageClient = $this->prophesize(Client::class);
5053
$this->vonageClient->getApiUrl()->willReturn('https://api.nexmo.com');
5154
$this->vonageClient->getCredentials()->willReturn(
@@ -88,7 +91,7 @@ public function testGetApplication($payload, $id, $expectsError): void
8891
$this->vonageClient->send(Argument::that(function (RequestInterface $request) use ($id) {
8992
$this->assertEquals('/v2/applications/' . $id, $request->getUri()->getPath());
9093
$this->assertEquals('api.nexmo.com', $request->getUri()->getHost());
91-
$this->assertRequestMethod('GET', $request);
94+
$this->assertRequestMethod('GET', $request);
9295
return true;
9396
}))->willReturn($this->getResponse());
9497

@@ -552,12 +555,4 @@ public function testCannotSetUnknownRegion(): void
552555
$application->setName('my application');
553556
$application->getVoiceConfig()->setRegion('eu-west-1');
554557
}
555-
556-
/**
557-
* Get the API response we'd expect for a call to the API.
558-
*/
559-
protected function getResponse(string $type = 'success', int $status = 200): Response
560-
{
561-
return new Response(fopen(__DIR__ . '/responses/' . $type . '.json', 'rb'), $status);
562-
}
563558
}

test/Client/Credentials/Handler/GnpHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Vonage\Client\Credentials\Gnp;
1212
use PHPUnit\Framework\TestCase;
1313
use Vonage\Client\Credentials\Handler\SimSwapGnpHandler;
14-
use VonageTest\Psr7AssertionTrait;
14+
use VonageTest\Traits\Psr7AssertionTrait;
1515

1616
class GnpHandlerTest extends TestCase
1717
{

test/Conversation/ClientTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
namespace VonageTest\Conversation;
66

77
use Laminas\Diactoros\Request;
8-
use Laminas\Diactoros\Response;
98
use Prophecy\Argument;
109
use Prophecy\Prophecy\ObjectProphecy;
11-
use VonageTest\Traits\Psr7AssertionTrait;
1210
use Vonage\Client;
1311
use Vonage\Client\APIResource;
1412
use Vonage\Conversation\Client as ConversationClient;
@@ -27,11 +25,14 @@
2725
use Vonage\Conversation\Filter\ListMembersFilter;
2826
use Vonage\Conversation\Filter\ListUserConversationsFilter;
2927
use Vonage\Entity\IterableAPICollection;
28+
use VonageTest\Traits\HTTPTestTrait;
29+
use VonageTest\Traits\Psr7AssertionTrait;
3030
use VonageTest\VonageTestCase;
3131

3232
class ClientTest extends VonageTestCase
3333
{
3434
use Psr7AssertionTrait;
35+
use HTTPTestTrait;
3536

3637
protected ObjectProphecy $vonageClient;
3738
protected ConversationClient $conversationsClient;
@@ -40,6 +41,8 @@ class ClientTest extends VonageTestCase
4041

4142
public function setUp(): void
4243
{
44+
$this->responsesDirectory = __DIR__ . '/Fixtures/Responses';
45+
4346
$this->vonageClient = $this->prophesize(Client::class);
4447
$this->vonageClient->getRestUrl()->willReturn('https://api.nexmo.com');
4548
$this->vonageClient->getCredentials()->willReturn(
@@ -795,9 +798,4 @@ public function testWillDeleteEvent(): void
795798

796799
$this->assertTrue($response);
797800
}
798-
799-
protected function getResponse(string $identifier, int $status = 200): Response
800-
{
801-
return new Response(fopen(__DIR__ . '/Fixtures/Responses/' . $identifier . '.json', 'rb'), $status);
802-
}
803801
}

test/Conversion/ClientTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
namespace VonageTest\Conversion;
66

7-
use Laminas\Diactoros\Response;
87
use PHPUnit\Framework\MockObject\MockObject;
98
use Prophecy\Argument;
109
use Psr\Http\Client\ClientExceptionInterface;
1110
use Psr\Http\Message\RequestInterface;
12-
use VonageTest\Traits\Psr7AssertionTrait;
1311
use Vonage\Client;
1412
use Vonage\Client as VonageClient;
1513
use Vonage\Client\APIResource;
1614
use Vonage\Client\Exception\Exception as ClientException;
1715
use Vonage\Client\Exception\Request as RequestException;
1816
use Vonage\Client\Exception\Server as ServerException;
1917
use Vonage\Conversion\Client as ConversionClient;
18+
use VonageTest\Traits\HTTPTestTrait;
19+
use VonageTest\Traits\Psr7AssertionTrait;
2020
use VonageTest\VonageTestCase;
21-
use function fopen;
2221

2322
class ClientTest extends VonageTestCase
2423
{
2524
use Psr7AssertionTrait;
25+
use HTTPTestTrait;
2626

2727
/**
2828
* @var Client|MockObject
@@ -43,6 +43,8 @@ class ClientTest extends VonageTestCase
4343

4444
public function setUp(): void
4545
{
46+
$this->responsesDirectory = 'data://text/plain,';
47+
4648
$this->vonageClient = $this->prophesize(VonageClient::class);
4749
$this->vonageClient->getRestUrl()->willReturn('https://rest.nexmo.com');
4850
$this->vonageClient->getApiUrl()->willReturn('https://api.nexmo.com');
@@ -135,12 +137,4 @@ public function testVoiceWithoutTimestamp(): void
135137

136138
$this->conversionClient->voice('ABC123', true);
137139
}
138-
139-
/**
140-
* Get the API response we'd expect for a call to the API.
141-
*/
142-
protected function getResponse(): Response
143-
{
144-
return new Response(fopen('data://text/plain,', 'rb'), 200);
145-
}
146140
}

test/FixedVersionClient.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)