|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Class OAuthProviderFactoryTest |
| 4 | + * |
| 5 | + * @created 11.04.2024 |
| 6 | + * @author smiley <smiley@chillerlan.net> |
| 7 | + * @copyright 2024 smiley |
| 8 | + * @license MIT |
| 9 | + * |
| 10 | + * @phan-file-suppress PhanUndeclaredProperty |
| 11 | + */ |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace chillerlan\OAuthTest\Core; |
| 15 | + |
| 16 | +use chillerlan\OAuth\Core\OAuthInterface; |
| 17 | +use chillerlan\OAuth\OAuthProviderFactory; |
| 18 | +use chillerlan\OAuth\Providers\ProviderException; |
| 19 | +use chillerlan\OAuthTest\Providers\DummyOAuth1Provider; |
| 20 | +use chillerlan\OAuthTest\Providers\ProviderUnitTestHttpClientFactory; |
| 21 | +use chillerlan\PHPUnitHttp\HttpFactoryTrait; |
| 22 | +use PHPUnit\Framework\TestCase; |
| 23 | +use function realpath; |
| 24 | + |
| 25 | +/** |
| 26 | + * |
| 27 | + */ |
| 28 | +class OAuthProviderFactoryTest extends TestCase{ |
| 29 | + use HttpFactoryTrait; |
| 30 | + |
| 31 | + protected const CACERT = __DIR__.'/../cacert.pem'; |
| 32 | + |
| 33 | + protected string $HTTP_CLIENT_FACTORY = ProviderUnitTestHttpClientFactory::class; |
| 34 | + |
| 35 | + protected function setUp():void{ |
| 36 | + $this->initFactories(realpath($this::CACERT)); |
| 37 | + |
| 38 | + $this->providerFactory = new OAuthProviderFactory( |
| 39 | + $this->httpClient, |
| 40 | + $this->requestFactory, |
| 41 | + $this->streamFactory, |
| 42 | + $this->uriFactory, |
| 43 | + ); |
| 44 | + |
| 45 | + } |
| 46 | + |
| 47 | + public function testGetProvider():void{ |
| 48 | + $provider = $this->providerFactory->getProvider(DummyOAuth1Provider::class); |
| 49 | + |
| 50 | + $this::assertInstanceOf(OAuthInterface::class, $provider); |
| 51 | + } |
| 52 | + |
| 53 | + public function testGetProviderInvalidProviderClassException():void{ |
| 54 | + $this->expectException(ProviderException::class); |
| 55 | + $this->expectExceptionMessage('invalid provider class given'); |
| 56 | + |
| 57 | + $this->providerFactory->getProvider('\\some\\unknown\\class'); |
| 58 | + } |
| 59 | + |
| 60 | +} |
0 commit comments