mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-26 16:52:04 +05:30
Use reflection instead of extension in test
This commit is contained in:
parent
c4c354e2df
commit
a92a274d15
@ -117,35 +117,31 @@ class AuthorizationServerTest extends TestCase
|
|||||||
$privateKey = 'file://' . __DIR__ . '/Stubs/private.key';
|
$privateKey = 'file://' . __DIR__ . '/Stubs/private.key';
|
||||||
$encryptionKey = 'file://' . __DIR__ . '/Stubs/public.key';
|
$encryptionKey = 'file://' . __DIR__ . '/Stubs/public.key';
|
||||||
|
|
||||||
$server = new class($clientRepository, $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(), $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(), $privateKey, $encryptionKey) extends AuthorizationServer {
|
$server = new AuthorizationServer(
|
||||||
protected function getResponseType()
|
$clientRepository,
|
||||||
{
|
$this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(),
|
||||||
$this->responseType = new class extends BearerTokenResponse {
|
$this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(),
|
||||||
/* @return null|CryptKey */
|
'file://' . __DIR__ . '/Stubs/private.key',
|
||||||
public function getPrivateKey()
|
'file://' . __DIR__ . '/Stubs/public.key'
|
||||||
{
|
);
|
||||||
return $this->privateKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEncryptionKey()
|
|
||||||
{
|
|
||||||
return $this->encryptionKey;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return parent::getResponseType();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$abstractGrantReflection = new \ReflectionClass($server);
|
$abstractGrantReflection = new \ReflectionClass($server);
|
||||||
$method = $abstractGrantReflection->getMethod('getResponseType');
|
$method = $abstractGrantReflection->getMethod('getResponseType');
|
||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
$responseType = $method->invoke($server);
|
$responseType = $method->invoke($server);
|
||||||
|
|
||||||
$this->assertInstanceOf(BearerTokenResponse::class, $responseType);
|
$responseTypeReflection = new \ReflectionClass($responseType);
|
||||||
|
|
||||||
|
$privateKeyProperty = $responseTypeReflection->getProperty('privateKey');
|
||||||
|
$privateKeyProperty->setAccessible(true);
|
||||||
|
|
||||||
|
$encryptionKeyProperty = $responseTypeReflection->getProperty('encryptionKey');
|
||||||
|
$encryptionKeyProperty->setAccessible(true);
|
||||||
|
|
||||||
// generated instances should have keys setup
|
// generated instances should have keys setup
|
||||||
$this->assertSame($privateKey, $responseType->getPrivateKey()->getKeyPath());
|
$this->assertSame($privateKey, $privateKeyProperty->getValue($responseType)->getKeyPath());
|
||||||
$this->assertSame($encryptionKey, $responseType->getEncryptionKey());
|
$this->assertSame($encryptionKey, $encryptionKeyProperty->getValue($responseType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMultipleRequestsGetDifferentResponseTypeInstances()
|
public function testMultipleRequestsGetDifferentResponseTypeInstances()
|
||||||
|
Loading…
Reference in New Issue
Block a user