diff --git a/tests/AuthorizationValidators/BearerTokenValidatorTest.php b/tests/AuthorizationValidators/BearerTokenValidatorTest.php index 25c7b188..69e56995 100644 --- a/tests/AuthorizationValidators/BearerTokenValidatorTest.php +++ b/tests/AuthorizationValidators/BearerTokenValidatorTest.php @@ -28,8 +28,7 @@ class BearerTokenValidatorTest extends TestCase ->set('scopes', 'scope1 scope2 scope3 scope4') ->getToken(); - $request = new ServerRequest(); - $request = $request->withHeader('authorization', sprintf('Bearer %s', $unsignedJwt)); + $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $unsignedJwt)); $this->expectException(\League\OAuth2\Server\Exception\OAuthServerException::class); $this->expectExceptionCode(9); diff --git a/tests/Grant/AbstractGrantTest.php b/tests/Grant/AbstractGrantTest.php index ea0afbca..a4b94264 100644 --- a/tests/Grant/AbstractGrantTest.php +++ b/tests/Grant/AbstractGrantTest.php @@ -30,8 +30,7 @@ class AbstractGrantTest extends TestCase $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withHeader('Authorization', 'Basic ' . base64_encode('Open:Sesame')); + $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Basic ' . base64_encode('Open:Sesame')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -44,8 +43,7 @@ class AbstractGrantTest extends TestCase $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withHeader('Authorization', 'Basic ' . base64_encode('Open:')); + $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Basic ' . base64_encode('Open:')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -58,8 +56,7 @@ class AbstractGrantTest extends TestCase $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withHeader('Authorization', 'Foo ' . base64_encode('Open:Sesame')); + $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Foo ' . base64_encode('Open:Sesame')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -72,8 +69,7 @@ class AbstractGrantTest extends TestCase $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withHeader('Authorization', 'Basic ||'); + $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Basic ||'); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -86,8 +82,7 @@ class AbstractGrantTest extends TestCase $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withHeader('Authorization', 'Basic ' . base64_encode('OpenSesame')); + $serverRequest = (new ServerRequest())->withHeader('Authorization', 'Basic ' . base64_encode('OpenSesame')); $basicAuthMethod = $abstractGrantReflection->getMethod('getBasicAuthCredentials'); $basicAuthMethod->setAccessible(true); @@ -107,12 +102,10 @@ class AbstractGrantTest extends TestCase $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody( - [ - 'client_id' => 'foo', - ] - ); + $serverRequest = (new ServerRequest())->withParsedBody([ + 'client_id' => 'foo', + ]); + $validateClientMethod = $abstractGrantReflection->getMethod('validateClient'); $validateClientMethod->setAccessible(true); @@ -133,14 +126,12 @@ class AbstractGrantTest extends TestCase $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody( - [ - 'client_id' => 'foo', - 'client_secret' => 'bar', - 'redirect_uri' => 'http://foo/bar', - ] - ); + $serverRequest = (new ServerRequest())->withParsedBody([ + 'client_id' => 'foo', + 'client_secret' => 'bar', + 'redirect_uri' => 'http://foo/bar', + ]); + $validateClientMethod = $abstractGrantReflection->getMethod('validateClient'); $validateClientMethod->setAccessible(true); @@ -148,7 +139,6 @@ class AbstractGrantTest extends TestCase $this->assertEquals($client, $result); } - public function testValidateClientMissingClientId() { $client = new ClientEntity(); @@ -181,8 +171,7 @@ class AbstractGrantTest extends TestCase $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', ]); @@ -205,8 +194,7 @@ class AbstractGrantTest extends TestCase $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'foo', ]); @@ -232,8 +220,7 @@ class AbstractGrantTest extends TestCase $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', 'redirect_uri' => 'http://bar/foo', ]); @@ -259,8 +246,7 @@ class AbstractGrantTest extends TestCase $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', 'redirect_uri' => 'http://bar/foo', ]); @@ -284,8 +270,7 @@ class AbstractGrantTest extends TestCase $abstractGrantReflection = new \ReflectionClass($grantMock); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', ]); @@ -303,8 +288,7 @@ class AbstractGrantTest extends TestCase $grantMock = $this->getMockForAbstractClass(AbstractGrant::class); $grantMock->method('getIdentifier')->willReturn('foobar'); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'grant_type' => 'foobar', ]); @@ -416,8 +400,7 @@ class AbstractGrantTest extends TestCase $method = $abstractGrantReflection->getMethod('getCookieParameter'); $method->setAccessible(true); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withCookieParams([ + $serverRequest = (new ServerRequest())->withCookieParams([ 'foo' => 'bar', ]); diff --git a/tests/Grant/ClientCredentialsGrantTest.php b/tests/Grant/ClientCredentialsGrantTest.php index b02f1190..54be52fd 100644 --- a/tests/Grant/ClientCredentialsGrantTest.php +++ b/tests/Grant/ClientCredentialsGrantTest.php @@ -48,13 +48,10 @@ class ClientCredentialsGrantTest extends TestCase $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody( - [ - 'client_id' => 'foo', - 'client_secret' => 'bar', - ] - ); + $serverRequest = (new ServerRequest())->withParsedBody([ + 'client_id' => 'foo', + 'client_secret' => 'bar', + ]); $responseType = new StubResponseType(); $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); diff --git a/tests/Grant/PasswordGrantTest.php b/tests/Grant/PasswordGrantTest.php index 4b7de98a..6568d06a 100644 --- a/tests/Grant/PasswordGrantTest.php +++ b/tests/Grant/PasswordGrantTest.php @@ -64,15 +64,12 @@ class PasswordGrantTest extends TestCase $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody( - [ - 'client_id' => 'foo', - 'client_secret' => 'bar', - 'username' => 'foo', - 'password' => 'bar', - ] - ); + $serverRequest = (new ServerRequest())->withParsedBody([ + 'client_id' => 'foo', + 'client_secret' => 'bar', + 'username' => 'foo', + 'password' => 'bar', + ]); $responseType = new StubResponseType(); $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); @@ -110,15 +107,12 @@ class PasswordGrantTest extends TestCase $grant->setDefaultScope(self::DEFAULT_SCOPE); $grant->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key')); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody( - [ - 'client_id' => 'foo', - 'client_secret' => 'bar', - 'username' => 'foo', - 'password' => 'bar', - ] - ); + $serverRequest = (new ServerRequest())->withParsedBody([ + 'client_id' => 'foo', + 'client_secret' => 'bar', + 'username' => 'foo', + 'password' => 'bar', + ]); $responseType = new StubResponseType(); $grant->respondToAccessTokenRequest($serverRequest, $responseType, new \DateInterval('PT5M')); diff --git a/tests/Grant/RefreshTokenGrantTest.php b/tests/Grant/RefreshTokenGrantTest.php index 632cbe80..21a5eeb8 100644 --- a/tests/Grant/RefreshTokenGrantTest.php +++ b/tests/Grant/RefreshTokenGrantTest.php @@ -80,8 +80,7 @@ class RefreshTokenGrantTest extends TestCase ) ); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $oldRefreshToken, @@ -137,8 +136,7 @@ class RefreshTokenGrantTest extends TestCase ) ); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody([ + $serverRequest = (new ServerRequest())->withParsedBody([ 'client_id' => 'foo', 'client_secret' => 'bar', 'refresh_token' => $oldRefreshToken, @@ -192,15 +190,12 @@ class RefreshTokenGrantTest extends TestCase ) ); - $serverRequest = new ServerRequest(); - $serverRequest = $serverRequest->withParsedBody( - [ - 'client_id' => 'foo', - 'client_secret' => 'bar', - 'refresh_token' => $oldRefreshToken, - 'scope' => 'foo', - ] - ); + $serverRequest = (new ServerRequest())->withParsedBody([ + 'client_id' => 'foo', + 'client_secret' => 'bar', + 'refresh_token' => $oldRefreshToken, + 'scope' => 'foo', + ]); $responseType = new StubResponseType(); $grant->respondToAccessTokenRequest($serverRequest, $responseType, new DateInterval('PT5M')); diff --git a/tests/Middleware/ResourceServerMiddlewareTest.php b/tests/Middleware/ResourceServerMiddlewareTest.php index 7210567b..4f2d3079 100644 --- a/tests/Middleware/ResourceServerMiddlewareTest.php +++ b/tests/Middleware/ResourceServerMiddlewareTest.php @@ -35,8 +35,7 @@ class ResourceServerMiddlewareTest extends TestCase $token = (string) $accessToken; - $request = new ServerRequest(); - $request = $request->withHeader('authorization', sprintf('Bearer %s', $token)); + $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $token)); $middleware = new ResourceServerMiddleware($server); $response = $middleware->__invoke( @@ -71,8 +70,7 @@ class ResourceServerMiddlewareTest extends TestCase $token = (string) $accessToken; - $request = new ServerRequest(); - $request = $request->withHeader('authorization', sprintf('Bearer %s', $token)); + $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $token)); $middleware = new ResourceServerMiddleware($server); $response = $middleware->__invoke( @@ -95,8 +93,7 @@ class ResourceServerMiddlewareTest extends TestCase 'file://' . __DIR__ . '/../Stubs/public.key' ); - $request = new ServerRequest(); - $request = $request->withHeader('authorization', ''); + $request = (new ServerRequest())->withHeader('authorization', ''); $middleware = new ResourceServerMiddleware($server); $response = $middleware->__invoke( diff --git a/tests/ResponseTypes/BearerResponseTypeTest.php b/tests/ResponseTypes/BearerResponseTypeTest.php index 97bc37aa..0c4a46fc 100644 --- a/tests/ResponseTypes/BearerResponseTypeTest.php +++ b/tests/ResponseTypes/BearerResponseTypeTest.php @@ -142,8 +142,7 @@ class BearerResponseTypeTest extends TestCase $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = new ServerRequest(); - $request = $request->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); + $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); $request = $authorizationValidator->validateAuthorization($request); @@ -185,8 +184,7 @@ class BearerResponseTypeTest extends TestCase $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = new ServerRequest(); - $request = $request->withHeader('authorization', sprintf('Bearer %s', $json->access_token . 'foo')); + $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $json->access_token . 'foo')); try { $authorizationValidator->validateAuthorization($request); @@ -231,8 +229,7 @@ class BearerResponseTypeTest extends TestCase $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = new ServerRequest(); - $request = $request->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); + $request = (new ServerRequest())->withHeader('authorization', sprintf('Bearer %s', $json->access_token)); try { $authorizationValidator->validateAuthorization($request); @@ -255,8 +252,7 @@ class BearerResponseTypeTest extends TestCase $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = new ServerRequest(); - $request = $request->withHeader('authorization', 'Bearer blah'); + $request = (new ServerRequest())->withHeader('authorization', 'Bearer blah'); try { $authorizationValidator->validateAuthorization($request); @@ -279,8 +275,7 @@ class BearerResponseTypeTest extends TestCase $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPublicKey(new CryptKey('file://' . __DIR__ . '/../Stubs/public.key')); - $request = new ServerRequest(); - $request = $request->withHeader('authorization', 'Bearer blah.blah.blah'); + $request = (new ServerRequest())->withHeader('authorization', 'Bearer blah.blah.blah'); try { $authorizationValidator->validateAuthorization($request);