Skip to content

Commit

Permalink
Added unit test for #472
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank committed Mar 27, 2024
1 parent 29df1c0 commit dccb3ff
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/Subaccount/ClientFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace VonageTest\Subaccount;

use PHPUnit\Framework\Exception;
use PHPUnit\Framework\ExpectationFailedException;
use Prophecy\Prophecy\ObjectProphecy;
use SebastianBergmann\RecursionContext\InvalidArgumentException;
use Vonage\Client;
use Vonage\Client\APIResource;
use Vonage\Client\Factory\MapFactory;
use Vonage\Subaccount\Client as SubaccountClient;
use Vonage\Subaccount\ClientFactory;
use VonageTest\Psr7AssertionTrait;
use VonageTest\VonageTestCase;

class ClientFactoryTest extends VonageTestCase
{
use Psr7AssertionTrait;

protected APIResource $api;

protected Client|ObjectProphecy $vonageClient;

public function setUp(): void
{
$this->vonageClient = $this->prophesize(Client::class);
$this->vonageClient->getCredentials()->willReturn(
new Client\Credentials\Basic('abc', 'def'),
);
$this->vonageClient = $this->vonageClient->reveal();
}

/**
* Makes sure that the client factory returns the correct object instance
*
* @see https://github.com/Vonage/vonage-php-sdk-core/pull/472
*
* @return void
* @throws InvalidArgumentException
* @throws Exception
* @throws ExpectationFailedException
*/
public function testFactoryMakeCorrectClient(): void
{
$container = new MapFactory(
[
APIResource::class => APIResource::class,
],
$this->vonageClient
);

$factory = new ClientFactory();
$client = $factory($container);
$this->assertInstanceOf(SubaccountClient::class, $client);
}
}

0 comments on commit dccb3ff

Please sign in to comment.