|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace VonageTest\Subaccount; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Exception; |
| 8 | +use PHPUnit\Framework\ExpectationFailedException; |
| 9 | +use Prophecy\Prophecy\ObjectProphecy; |
| 10 | +use SebastianBergmann\RecursionContext\InvalidArgumentException; |
| 11 | +use Vonage\Client; |
| 12 | +use Vonage\Client\APIResource; |
| 13 | +use Vonage\Client\Factory\MapFactory; |
| 14 | +use Vonage\Subaccount\Client as SubaccountClient; |
| 15 | +use Vonage\Subaccount\ClientFactory; |
| 16 | +use VonageTest\Psr7AssertionTrait; |
| 17 | +use VonageTest\VonageTestCase; |
| 18 | + |
| 19 | +class ClientFactoryTest extends VonageTestCase |
| 20 | +{ |
| 21 | + use Psr7AssertionTrait; |
| 22 | + |
| 23 | + protected APIResource $api; |
| 24 | + |
| 25 | + protected Client|ObjectProphecy $vonageClient; |
| 26 | + |
| 27 | + public function setUp(): void |
| 28 | + { |
| 29 | + $this->vonageClient = $this->prophesize(Client::class); |
| 30 | + $this->vonageClient->getCredentials()->willReturn( |
| 31 | + new Client\Credentials\Basic('abc', 'def'), |
| 32 | + ); |
| 33 | + $this->vonageClient = $this->vonageClient->reveal(); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Makes sure that the client factory returns the correct object instance |
| 38 | + * |
| 39 | + * @see https://github.com/Vonage/vonage-php-sdk-core/pull/472 |
| 40 | + * |
| 41 | + * @return void |
| 42 | + * @throws InvalidArgumentException |
| 43 | + * @throws Exception |
| 44 | + * @throws ExpectationFailedException |
| 45 | + */ |
| 46 | + public function testFactoryMakeCorrectClient(): void |
| 47 | + { |
| 48 | + $container = new MapFactory( |
| 49 | + [ |
| 50 | + APIResource::class => APIResource::class, |
| 51 | + ], |
| 52 | + $this->vonageClient |
| 53 | + ); |
| 54 | + |
| 55 | + $factory = new ClientFactory(); |
| 56 | + $client = $factory($container); |
| 57 | + $this->assertInstanceOf(SubaccountClient::class, $client); |
| 58 | + } |
| 59 | +} |
0 commit comments