-
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.
Test all client factory configurations
- Loading branch information
Showing
33 changed files
with
1,347 additions
and
24 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Application; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client; | ||
use Vonage\Client\APIResource; | ||
use Vonage\Client\Factory\MapFactory; | ||
use Vonage\Application\ClientFactory; | ||
|
||
class ClientFactoryTest extends TestCase | ||
{ | ||
public function testInvokeCreatesClientWithConfiguredApiResource(): void | ||
{ | ||
$mockServices = [ | ||
'account' => ClientFactory::class, | ||
APIResource::class => APIResource::class, | ||
]; | ||
|
||
$mockClient = $this->createMock(Client::class); | ||
$container = new MapFactory($mockServices, $mockClient); | ||
$factory = new ClientFactory(); | ||
|
||
$result = $factory($container); | ||
$this->assertInstanceOf(\Vonage\Application\Client::class, $result); | ||
$this->assertEquals('/v2/applications', $result->getAPIResource()->getBaseUri()); | ||
$this->assertInstanceOf(Client\Credentials\Handler\BasicHandler::class, $result->getAPIResource() | ||
->getAuthHandlers()[0]); | ||
$this->assertEquals('applications', $result->getAPIResource()->getCollectionName()); | ||
} | ||
} |
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,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Vonage\Client\Callback; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client\Callback\Callback; | ||
use RuntimeException; | ||
use InvalidArgumentException; | ||
|
||
class CallbackTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
// Mocking the $_GET and $_POST superglobals for testing purposes | ||
$_GET = [ | ||
'key1' => 'value1', | ||
'key2' => 'value2', | ||
]; | ||
|
||
$_POST = [ | ||
'key3' => 'value3', | ||
'key4' => 'value4', | ||
]; | ||
} | ||
|
||
public function testConstructorWithMissingKeys(): void | ||
{ | ||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('missing expected callback keys: key1, key2'); | ||
|
||
$callback = new class (['key3' => 'value3']) extends Callback { | ||
protected array $expected = ['key1', 'key2']; | ||
}; | ||
} | ||
|
||
public function testConstructorWithAllKeys(): void | ||
{ | ||
$callback = new class ([ | ||
'key1' => 'value1', | ||
'key2' => 'value2', | ||
]) extends Callback { | ||
protected array $expected = ['key1', 'key2']; | ||
}; | ||
|
||
$this->assertSame([ | ||
'key1' => 'value1', | ||
'key2' => 'value2', | ||
], $callback->getData()); | ||
} | ||
|
||
public function testFromEnvPost(): void | ||
{ | ||
$callback = Callback::fromEnv(Callback::ENV_POST); | ||
|
||
$this->assertInstanceOf(Callback::class, $callback); | ||
$this->assertSame([ | ||
'key3' => 'value3', | ||
'key4' => 'value4', | ||
], $callback->getData()); | ||
} | ||
|
||
public function testFromEnvGet(): void | ||
{ | ||
$callback = Callback::fromEnv(Callback::ENV_GET); | ||
|
||
$this->assertInstanceOf(Callback::class, $callback); | ||
$this->assertSame([ | ||
'key1' => 'value1', | ||
'key2' => 'value2', | ||
], $callback->getData()); | ||
} | ||
|
||
public function testFromEnvAll(): void | ||
{ | ||
$callback = Callback::fromEnv(Callback::ENV_ALL); | ||
|
||
$this->assertInstanceOf(Callback::class, $callback); | ||
$this->assertSame([ | ||
'key1' => 'value1', | ||
'key2' => 'value2', | ||
'key3' => 'value3', | ||
'key4' => 'value4', | ||
], $callback->getData()); | ||
} | ||
|
||
public function testFromEnvInvalidSource(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('invalid source: invalid'); | ||
|
||
Callback::fromEnv('invalid'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VonageTest\Conversation; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Vonage\Client; | ||
use Vonage\Client\APIResource; | ||
use Vonage\Client\Factory\MapFactory; | ||
use Vonage\Conversation\ClientFactory; | ||
|
||
class ClientFactoryTest extends TestCase | ||
{ | ||
public function testInvokeCreatesClientWithConfiguredApiResource(): void | ||
{ | ||
$mockServices = [ | ||
'conversation' => ClientFactory::class, | ||
APIResource::class => APIResource::class, | ||
]; | ||
|
||
$mockClient = $this->createMock(Client::class); | ||
$container = new MapFactory($mockServices, $mockClient); | ||
$factory = new ClientFactory(); | ||
|
||
$result = $factory($container); | ||
$this->assertInstanceOf(\Vonage\Conversation\Client::class, $result); | ||
$this->assertEquals('https://api.nexmo.com/v1/conversations', $result->getAPIResource()->getBaseUrl()); | ||
$this->assertInstanceOf(Client\Credentials\Handler\KeypairHandler::class, $result->getAPIResource() | ||
->getAuthHandlers()[0]); | ||
$this->assertFalse($result->getAPIResource()->errorsOn200()); | ||
$this->assertTrue($result->getAPIResource()->isHAL()); | ||
} | ||
} |
Oops, something went wrong.