-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage for hardcoded error handler
- Loading branch information
Showing
2 changed files
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ protected function getException(ResponseInterface $response): ClientException\Ex | |
|
||
if ($status === 402) { | ||
$e = new ClientException\Request('This endpoint may need activating on your account. ' . | ||
'"Please email [email protected] for more information', $status); | ||
'Please email [email protected] for more information', $status); | ||
} elseif ($status >= 400 && $status < 500) { | ||
$e = new ClientException\Request($body['error_title'], $status); | ||
} elseif ($status >= 500 && $status < 600) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,12 @@ | |
|
||
namespace VonageTest\Conversion; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Prophecy\Argument; | ||
use Psr\Http\Client\ClientExceptionInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
use ReflectionClass; | ||
use Vonage\Client; | ||
use Vonage\Client as VonageClient; | ||
use Vonage\Client\APIResource; | ||
|
@@ -140,12 +142,38 @@ public function testVoiceWithoutTimestamp(): void | |
|
||
public function testExceptionHandler(): void | ||
{ | ||
$this->expectException(Client\Exception\Request::class); | ||
$reflection = new ReflectionClass($this->conversionClient); | ||
$method = $reflection->getMethod('getException'); | ||
$method->setAccessible(true); | ||
|
||
$this->vonageClient->send(Argument::that(function (RequestInterface $request) { | ||
return true; | ||
}))->willReturn($this->getResponse('error', 402)); | ||
$response = new Response(402); | ||
|
||
$this->conversionClient->sms('ABC123', true, '123456'); | ||
$return = $method->invoke($this->conversionClient, $response); | ||
$this->assertEquals('This endpoint may need activating on your account. Please email [email protected] for more information', $return->getMessage()); | ||
$this->assertInstanceOf(Client\Exception\Request::class, $return); | ||
|
||
$serverResponse = new Response(500, [], json_encode([ | ||
'error_title' => 'Vonage Server Error', | ||
])); | ||
|
||
$return2 = $method->invoke($this->conversionClient, $serverResponse); | ||
$this->assertEquals('Vonage Server Error', $return2->getMessage()); | ||
$this->assertInstanceOf(Client\Exception\Server::class, $return2); | ||
|
||
$unexpected = new Response(201, [], json_encode([ | ||
'error_title' => 'this is not an error', | ||
])); | ||
|
||
$return3 = $method->invoke($this->conversionClient, $unexpected); | ||
$this->assertEquals('Unexpected HTTP Status Code (201)', $return3->getMessage()); | ||
$this->assertInstanceOf(Client\Exception\Exception::class, $return3); | ||
|
||
$notFound = new Response(404, [], json_encode([ | ||
'error_title' => 'Not Found', | ||
])); | ||
|
||
$return4 = $method->invoke($this->conversionClient, $notFound); | ||
$this->assertEquals('Not Found', $return4->getMessage()); | ||
$this->assertInstanceOf(Client\Exception\Request::class, $return4); | ||
} | ||
} |