Update PHPUnit, run static analysis on tests

This commit is contained in:
Lukáš Unger 2018-02-11 23:14:34 +01:00
parent 97089ad49e
commit 1f87c7a7be
No known key found for this signature in database
GPG Key ID: 48E84B8B7A223C26
9 changed files with 33 additions and 30 deletions

View File

@ -16,7 +16,7 @@ install:
script:
- vendor/bin/phpunit
- vendor/bin/phpstan analyse -l 6 src
- vendor/bin/phpstan analyse -l 6 -c phpstan.neon src tests
branches:
only:

View File

@ -13,9 +13,10 @@
"defuse/php-encryption": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.38 || ^5.7.21",
"phpunit/phpunit": "^6.3 || ^7.0",
"zendframework/zend-diactoros": "^1.0",
"phpstan/phpstan": "^0.9.2"
"phpstan/phpstan": "^0.9.2",
"phpstan/phpstan-phpunit": "^0.9.4"
},
"repositories": [
{

9
phpstan.neon Normal file
View File

@ -0,0 +1,9 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-phpunit/strictRules.neon
parameters:
ignoreErrors:
- '#Class Zend\\Diactoros\\ServerRequest constructor invoked with \d+ parameters, 0-6 required#'
- '#Parameter \#2 \$key of method Lcobucci\\JWT\\Builder::sign\(\) expects string, Lcobucci\\JWT\\Signer\\Key given#'
reportUnmatchedIgnoredErrors: false

View File

@ -236,10 +236,13 @@ class OAuthServerException extends \Exception
$this->redirectUri .= (strstr($this->redirectUri, '?') === false) ? '?' : '&';
}
return $response->withStatus(302)->withHeader('Location', $this->redirectUri . http_build_query($payload));
/** @var ResponseInterface $response */
$response = $response->withStatus(302)->withHeader('Location', $this->redirectUri . http_build_query($payload));
return $response;
}
foreach ($headers as $header => $content) {
/** @var ResponseInterface $response */
$response = $response->withHeader($header, $content);
}

View File

@ -35,6 +35,8 @@ class RedirectResponse extends AbstractResponseType
*/
public function generateHttpResponse(ResponseInterface $response)
{
return $response->withStatus(302)->withHeader('Location', $this->redirectUri);
/** @var ResponseInterface $response */
$response = $response->withStatus(302)->withHeader('Location', $this->redirectUri);
return $response;
}
}

View File

@ -198,16 +198,16 @@ class AuthorizationServerTest extends TestCase
$clientRepositoryMock->method('getClientEntity')->willReturn($client);
$grant = new AuthCodeGrant(
$this->getMock(AuthCodeRepositoryInterface::class),
$this->getMock(RefreshTokenRepositoryInterface::class),
$this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(),
$this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(),
new \DateInterval('PT10M')
);
$grant->setClientRepository($clientRepositoryMock);
$server = new AuthorizationServer(
$clientRepositoryMock,
$this->getMock(AccessTokenRepositoryInterface::class),
$this->getMock(ScopeRepositoryInterface::class),
$this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(),
$this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(),
'file://' . __DIR__ . '/Stubs/private.key',
'file://' . __DIR__ . '/Stubs/public.key'
);

View File

@ -20,9 +20,7 @@ class BearerResponseTypeTest extends TestCase
{
public function testGenerateHttpResponse()
{
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
$responseType = new BearerTokenResponse($accessTokenRepositoryMock);
$responseType = new BearerTokenResponse();
$responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$responseType->setEncryptionKey(base64_encode(random_bytes(36)));
@ -64,9 +62,7 @@ class BearerResponseTypeTest extends TestCase
public function testGenerateHttpResponseWithExtraParams()
{
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
$responseType = new BearerTokenResponseWithParams($accessTokenRepositoryMock);
$responseType = new BearerTokenResponseWithParams();
$responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$responseType->setEncryptionKey(base64_encode(random_bytes(36)));
@ -111,10 +107,7 @@ class BearerResponseTypeTest extends TestCase
public function testDetermineAccessTokenInHeaderValidToken()
{
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
$accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(false);
$responseType = new BearerTokenResponse($accessTokenRepositoryMock);
$responseType = new BearerTokenResponse();
$responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$responseType->setEncryptionKey(base64_encode(random_bytes(36)));
@ -158,9 +151,8 @@ class BearerResponseTypeTest extends TestCase
public function testDetermineAccessTokenInHeaderInvalidJWT()
{
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
$accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(false);
$responseType = new BearerTokenResponse($accessTokenRepositoryMock);
$responseType = new BearerTokenResponse();
$responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$responseType->setEncryptionKey(base64_encode(random_bytes(36)));
@ -247,9 +239,7 @@ class BearerResponseTypeTest extends TestCase
public function testDetermineAccessTokenInHeaderInvalidToken()
{
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
$responseType = new BearerTokenResponse($accessTokenRepositoryMock);
$responseType = new BearerTokenResponse();
$responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$responseType->setEncryptionKey(base64_encode(random_bytes(36)));
@ -273,9 +263,7 @@ class BearerResponseTypeTest extends TestCase
public function testDetermineMissingBearerInHeader()
{
$accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock();
$responseType = new BearerTokenResponse($accessTokenRepositoryMock);
$responseType = new BearerTokenResponse();
$responseType->setPrivateKey(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$responseType->setEncryptionKey(base64_encode(random_bytes(36)));

View File

@ -17,7 +17,7 @@ class CryptKeyTest extends TestCase
public function testKeyCreation()
{
$keyFile = __DIR__ . '/Stubs/public.key';
$keyFile = __DIR__ . '/../Stubs/public.key';
$key = new CryptKey($keyFile, 'secret');
$this->assertEquals('file://' . $keyFile, $key->getKeyPath());
@ -26,7 +26,7 @@ class CryptKeyTest extends TestCase
public function testKeyFileCreation()
{
$keyContent = file_get_contents(__DIR__ . '/Stubs/public.key');
$keyContent = file_get_contents(__DIR__ . '/../Stubs/public.key');
$key = new CryptKey($keyContent);
$this->assertEquals(
@ -34,7 +34,7 @@ class CryptKeyTest extends TestCase
$key->getKeyPath()
);
$keyContent = file_get_contents(__DIR__ . '/Stubs/private.key.crlf');
$keyContent = file_get_contents(__DIR__ . '/../Stubs/private.key.crlf');
$key = new CryptKey($keyContent);
$this->assertEquals(