Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
:octocat: separate test provider init
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Aug 1, 2023
1 parent d1d07fc commit 74849d9
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions tests/Providers/OAuthProviderTestAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace chillerlan\OAuthTest\Providers;

use chillerlan\OAuth\Core\{AccessToken, OAuthInterface, TokenInvalidate};
use chillerlan\OAuth\Core\{OAuth1Interface, OAuth2Interface, OAuthInterface, TokenInvalidate};
use chillerlan\OAuth\OAuthOptions;
use chillerlan\OAuth\Storage\{MemoryStorage, OAuthStorageInterface};
use chillerlan\Settings\SettingsContainerInterface;
Expand Down Expand Up @@ -39,10 +39,10 @@ abstract class OAuthProviderTestAbstract extends TestCase{
protected LoggerInterface $logger;

// OAuth related properties
protected OAuthOptions|SettingsContainerInterface $options;
protected OAuthInterface $provider;
protected OAuthStorageInterface $storage;
protected ReflectionClass $reflection; // reflection of the test subject
protected OAuthOptions|SettingsContainerInterface $options;
protected OAuthInterface|OAuth1Interface|OAuth2Interface $provider;
protected OAuthStorageInterface $storage;
protected ReflectionClass $reflection; // reflection of the test subject

protected string $FQN; // fully qualified class name of the test subject
protected array $testProperties = [];
Expand All @@ -63,19 +63,9 @@ protected function setUp():void{
$this->storage = $this->initStorage($this->options);
$this->http = $this->initHttp($this->options, $this->logger, $this->testResponses); // PSR-18 HTTP client
$this->reflection = new ReflectionClass($this->FQN);
$this->provider = $this->reflection->newInstanceArgs([$this->http, $this->options, $this->logger]);

$this->provider
->setStorage($this->storage)
->setRequestFactory($this->requestFactory)
->setStreamFactory($this->streamFactory)
->setUriFactory($this->uriFactory)
;

foreach($this->testProperties as $property => $value){
$this->reflection->getProperty($property)->setValue($this->provider, $value);
}
$this->provider = $this->initProvider();

$this->initTestProperties($this->testProperties);
}

protected function initFactories():void{
Expand Down Expand Up @@ -129,6 +119,25 @@ protected function initHttp(SettingsContainerInterface $options, LoggerInterface
return new ProviderTestHttpClient($responses, $this->responseFactory, $this->streamFactory);
}

protected function initProvider():OAuthInterface|OAuth1Interface|OAuth2Interface{
$provider = $this->reflection->newInstanceArgs([$this->http, $this->options, $this->logger]);

$provider
->setStorage($this->storage)
->setRequestFactory($this->requestFactory)
->setStreamFactory($this->streamFactory)
->setUriFactory($this->uriFactory)
;

return $provider;
}

protected function initTestProperties(array $properties):void{
foreach($properties as $property => $value){
$this->reflection->getProperty($property)->setValue($this->provider, $value);
}
}

public function testOAuthInstance():void{
$this::assertInstanceOf(OAuthInterface::class, $this->provider);
}
Expand All @@ -139,6 +148,7 @@ public function testProviderInstance():void{

public function testMagicGet():void{
$this::assertSame($this->reflection->getShortName(), $this->provider->serviceName);
/** @noinspection PhpUndefinedFieldInspection */
$this::assertNull($this->provider->foo);
}

Expand Down

0 comments on commit 74849d9

Please sign in to comment.