-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added exception and credentials testing
- Loading branch information
Showing
15 changed files
with
340 additions
and
14 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
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
36 changes: 36 additions & 0 deletions
36
test/Client/Credentials/Handler/SignatureBodyHandlerTest.php
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Credentials\Handler; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use Vonage\Client\Credentials\Handler\SignatureBodyHandler; | ||
use Vonage\Client\Credentials\SignatureSecret; | ||
use VonageTest\VonageTestCase; | ||
|
||
class SignatureBodyHandlerTest extends VonageTestCase | ||
{ | ||
public function testSignatureBodyHandler(): void | ||
{ | ||
$request = new Request( | ||
'POST', | ||
'/test', | ||
['Content-Type' => 'application/json'], | ||
json_encode(['foo' => 'bar']) | ||
); | ||
|
||
$credentials = new SignatureSecret('secret', 'sha256'); | ||
|
||
$handler = new SignatureBodyHandler(); | ||
$authRequest = $handler($request, $credentials); | ||
$authRequest->getBody()->rewind(); | ||
$newBody = $authRequest->getBody()->getContents(); | ||
$newBodyArray = json_decode($newBody, true); | ||
|
||
$this->assertIsArray($newBodyArray); | ||
$this->assertArrayHasKey('foo', $newBodyArray); | ||
$this->assertEquals('bar', $newBodyArray['foo']); | ||
$this->assertArrayHasKey('sig', $newBodyArray); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
test/Client/Credentials/Handler/SignatureQueryHandlerTest.php
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Credentials\Handler; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use Vonage\Client\Credentials\Handler\SignatureQueryHandler; | ||
use Vonage\Client\Credentials\SignatureSecret; | ||
use VonageTest\VonageTestCase; | ||
class SignatureQueryHandlerTest extends VonageTestCase | ||
{ | ||
public function testSignatureQueryHandler(): void | ||
{ | ||
$request = new Request( | ||
'POST', | ||
'/test', | ||
['Content-Type' => 'application/json'], | ||
json_encode(['foo' => 'bar']) | ||
); | ||
|
||
$credentials = new SignatureSecret('secret', 'sha256'); | ||
|
||
$handler = new SignatureQueryHandler(); | ||
$authRequest = $handler($request, $credentials); | ||
|
||
$this->assertStringContainsString('sig', $authRequest->getUri()->getQuery()); | ||
$this->assertStringContainsString('timestamp', $authRequest->getUri()->getQuery()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Credentials\Handler; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use Vonage\Client\Credentials\Basic; | ||
use Vonage\Client\Credentials\Handler\TokenBodyHandler; | ||
use VonageTest\VonageTestCase; | ||
|
||
class TokenBodyHandlerTest extends VonageTestCase | ||
{ | ||
public function testTokenBodyHandler(): void | ||
{ | ||
$request = new Request( | ||
'POST', | ||
'/test', | ||
['Content-Type' => 'application/json'], | ||
json_encode(['foo' => 'bar']) | ||
); | ||
|
||
$credentials = new Basic('secret', 'sha256'); | ||
|
||
$handler = new TokenBodyHandler(); | ||
$authRequest = $handler($request, $credentials); | ||
$authRequest->getBody()->rewind(); | ||
$newBody = $authRequest->getBody()->getContents(); | ||
$newBodyArray = json_decode($newBody, true); | ||
|
||
$this->assertIsArray($newBodyArray); | ||
$this->assertArrayHasKey('foo', $newBodyArray); | ||
$this->assertArrayHasKey('api_key', $newBodyArray); | ||
$this->assertArrayHasKey('api_secret', $newBodyArray); | ||
$this->assertEquals('bar', $newBodyArray['foo']); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Credentials\Handler; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use Vonage\Client\Credentials\Basic; | ||
use Vonage\Client\Credentials\Handler\TokenQueryHandler; | ||
use VonageTest\VonageTestCase; | ||
|
||
class TokenQueryHandlerTest extends VonageTestCase | ||
{ | ||
public function testTokenBodyHandler(): void | ||
{ | ||
$request = new Request( | ||
'POST', | ||
'/test', | ||
['Content-Type' => 'application/json'], | ||
json_encode(['foo' => 'bar']) | ||
); | ||
|
||
$credentials = new Basic('secret', 'sha256'); | ||
|
||
$handler = new TokenQueryHandler(); | ||
$authRequest = $handler($request, $credentials); | ||
|
||
$this->assertStringContainsString('api_key', $authRequest->getUri()->getQuery()); | ||
$this->assertStringContainsString('api_secret', $authRequest->getUri()->getQuery()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Exception\Conflict; | ||
|
||
class ConflictTest extends TestCase | ||
{ | ||
public function testExceptionCanBeThrown(): void | ||
{ | ||
$this->expectException(Conflict::class); | ||
|
||
throw new Conflict('Conflict occurred'); | ||
} | ||
|
||
public function testExceptionMessage(): void | ||
{ | ||
$message = 'Conflict occurred'; | ||
$exception = new Conflict($message); | ||
|
||
$this->assertSame($message, $exception->getMessage()); | ||
} | ||
|
||
public function testExceptionIsInstanceOfBaseException(): void | ||
{ | ||
$exception = new Conflict('Conflict occurred'); | ||
|
||
$this->assertInstanceOf(\Exception::class, $exception); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Exception\Credentials; | ||
|
||
class CredentialsTest extends TestCase | ||
{ | ||
public function testExceptionCanBeThrown(): void | ||
{ | ||
$this->expectException(Credentials::class); | ||
|
||
throw new Credentials('You are not authorised to perform this request'); | ||
} | ||
|
||
public function testExceptionMessage(): void | ||
{ | ||
$message = 'You are not authorised to perform this request'; | ||
$exception = new Credentials($message); | ||
|
||
$this->assertSame($message, $exception->getMessage()); | ||
} | ||
|
||
public function testExceptionIsInstanceOfBaseException(): void | ||
{ | ||
$exception = new Credentials('You are not authorised to perform this request'); | ||
|
||
$this->assertInstanceOf(\Exception::class, $exception); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Exception\NotFound; | ||
|
||
class NotFoundTest extends TestCase | ||
{ | ||
public function testExceptionCanBeThrown(): void | ||
{ | ||
$this->expectException(NotFound::class); | ||
|
||
throw new NotFound('You are not authorised to perform this request'); | ||
} | ||
|
||
public function testExceptionMessage(): void | ||
{ | ||
$message = 'You are not authorised to perform this request'; | ||
$exception = new NotFound($message); | ||
|
||
$this->assertSame($message, $exception->getMessage()); | ||
} | ||
|
||
public function testExceptionIsInstanceOfBaseException(): void | ||
{ | ||
$exception = new NotFound('You are not authorised to perform this request'); | ||
|
||
$this->assertInstanceOf(\Exception::class, $exception); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Exception\Request; | ||
|
||
class RequestTest extends TestCase | ||
{ | ||
public function testExceptionCanBeThrown(): void | ||
{ | ||
$this->expectException(Request::class); | ||
|
||
throw new Request('You are not authorised to perform this request'); | ||
} | ||
|
||
public function testExceptionMessage(): void | ||
{ | ||
$message = 'You are not authorised to perform this request'; | ||
$exception = new Request($message); | ||
|
||
$this->assertSame($message, $exception->getMessage()); | ||
} | ||
|
||
public function testExceptionIsInstanceOfBaseException(): void | ||
{ | ||
$exception = new Request('You are not authorised to perform this request'); | ||
|
||
$this->assertInstanceOf(\Exception::class, $exception); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Exception\Request; | ||
|
||
class ServerTest extends TestCase | ||
{ | ||
public function testExceptionCanBeThrown(): void | ||
{ | ||
$this->expectException(Request::class); | ||
|
||
throw new Request('No results found'); | ||
} | ||
|
||
public function testExceptionMessage(): void | ||
{ | ||
$message = 'No results found'; | ||
$exception = new Request($message); | ||
|
||
$this->assertSame($message, $exception->getMessage()); | ||
} | ||
|
||
public function testExceptionIsInstanceOfBaseException(): void | ||
{ | ||
$exception = new Request('No results found'); | ||
|
||
$this->assertInstanceOf(\Exception::class, $exception); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Client\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Exception\Request; | ||
|
||
class TransportTest extends TestCase | ||
{ | ||
public function testExceptionCanBeThrown(): void | ||
{ | ||
$this->expectException(Request::class); | ||
|
||
throw new Request('Response was empty'); | ||
} | ||
|
||
public function testExceptionMessage(): void | ||
{ | ||
$message = 'Response was empty'; | ||
$exception = new Request($message); | ||
|
||
$this->assertSame($message, $exception->getMessage()); | ||
} | ||
|
||
public function testExceptionIsInstanceOfBaseException(): void | ||
{ | ||
$exception = new Request('Response was empty'); | ||
|
||
$this->assertInstanceOf(\Exception::class, $exception); | ||
} | ||
} |
Oops, something went wrong.