Skip to content

Commit

Permalink
Merge 38892a8 into 75d697b
Browse files Browse the repository at this point in the history
  • Loading branch information
lookyman committed Nov 28, 2018
2 parents 75d697b + 38892a8 commit dab158e
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 35 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -27,6 +27,7 @@ script:
- ./vendor/bin/parallel-lint src test
- ./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml
- ./vendor/bin/phpcs src test --standard=psr12 -sp
- ./vendor/bin/phpstan analyse -l 3 src test

after_success:
- travis_retry php vendor/bin/coveralls
7 changes: 6 additions & 1 deletion composer.json
Expand Up @@ -12,7 +12,10 @@
"require-dev": {
"eloquent/liberator": "^2.0",
"eloquent/phony-phpunit": "^4.0",
"eloquent/phpstan-phony": "^0.3.0",
"jakub-onderka/php-parallel-lint": "^1.0",
"phpstan/phpstan": "^0.10.5",
"phpstan/phpstan-phpunit": "^0.10.0",
"phpunit/phpunit": "^7.4",
"squizlabs/php_codesniffer": "^3.3"
},
Expand Down Expand Up @@ -54,10 +57,12 @@
"lint": "parallel-lint src test",
"phpunit": "phpunit --verbose --colors=always",
"phpcs": "phpcs src test --standard=psr12 -sp --colors",
"phpstan": "phpstan analyse -l 3 src test",
"test": [
"@lint",
"@phpunit",
"@phpcs"
"@phpcs",
"@phpstan"
]
}
}
13 changes: 13 additions & 0 deletions phpstan.neon
@@ -0,0 +1,13 @@
includes:
- vendor/eloquent/phpstan-phony/phony.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon

services:
-
class: League\OAuth2\Client\Test\PHPStan\LiberatorExtension
tags: [phpstan.broker.dynamicStaticMethodReturnTypeExtension]

parameters:
ignoreErrors:
- '#Method League\\OAuth2\\Client\\Test\\Tool\\ProviderRedirectTraitTest::setRedirectLimit\(\) should return League\\OAuth2\\Client\\Provider\\AbstractProvider but returns \$this\(League\\OAuth2\\Client\\Test\\Tool\\ProviderRedirectTraitTest\)\.#'
4 changes: 2 additions & 2 deletions src/Provider/AbstractProvider.php
Expand Up @@ -667,7 +667,7 @@ protected function getContentType(ResponseInterface $response)
*
* @throws UnexpectedValueException
* @param ResponseInterface $response
* @return array
* @return array|string
*/
protected function parseResponse(ResponseInterface $response)
{
Expand Down Expand Up @@ -717,7 +717,7 @@ abstract protected function checkResponse(ResponseInterface $response, $data);
* Custom mapping of expiration, etc should be done here. Always call the
* parent method when overloading this method.
*
* @param mixed $result
* @param array $result
* @return array
*/
protected function prepareAccessTokenResponse(array $result)
Expand Down
2 changes: 1 addition & 1 deletion src/Tool/ProviderRedirectTrait.php
Expand Up @@ -102,7 +102,7 @@ public function getResponse(RequestInterface $request)
* Updates the redirect limit.
*
* @param integer $limit
* @return League\OAuth2\Client\Provider\AbstractProvider
* @return \League\OAuth2\Client\Provider\AbstractProvider
* @throws InvalidArgumentException
*/
public function setRedirectLimit($limit)
Expand Down
2 changes: 1 addition & 1 deletion src/Tool/RequestFactory.php
Expand Up @@ -29,7 +29,7 @@ class RequestFactory
* @param null|string $method HTTP method for the request.
* @param null|string $uri URI for the request.
* @param array $headers Headers for the message.
* @param string|resource|StreamInterface $body Message body.
* @param string|resource|\Psr\Http\Message\StreamInterface $body Message body.
* @param string $version HTTP protocol version.
*
* @return Request
Expand Down
2 changes: 1 addition & 1 deletion src/Tool/RequiredParameterTrait.php
Expand Up @@ -42,7 +42,7 @@ private function checkRequiredParameter($name, array $params)
/**
* Checks for multiple required parameters in a hash.
*
* @throws InvalidArgumentException
* @throws BadMethodCallException
* @param array $names
* @param array $params
* @return void
Expand Down
12 changes: 7 additions & 5 deletions test/src/Grant/GrantFactoryTest.php
Expand Up @@ -4,14 +4,13 @@

use League\OAuth2\Client\Grant\GrantFactory;
use League\OAuth2\Client\Grant\AbstractGrant;
use League\OAuth2\Client\Grant\Exception\InvalidGrantException;
use League\OAuth2\Client\Test\Grant\Fake as MockGrant;
use PHPUnit\Framework\TestCase;

class GrantFactoryTest extends TestCase
{
/**
* @var AbstractGrant
* @var GrantFactory
*/
protected $factory;

Expand Down Expand Up @@ -40,7 +39,7 @@ public function providerGetGrantDefaults()
}

/**
* @expectedException League\OAuth2\Client\Grant\Exception\InvalidGrantException
* @expectedException \League\OAuth2\Client\Grant\Exception\InvalidGrantException
*/
public function testGetInvalidGrantFails()
{
Expand Down Expand Up @@ -79,14 +78,17 @@ public function testIsGrant()
$this->assertFalse($this->factory->isGrant('stdClass'));
}

/**
* @doesNotPerformAssertions
*/
public function testCheckGrant()
{
$grant = $this->factory->getGrant('password');
$this->assertNull($this->factory->checkGrant($grant));
$this->factory->checkGrant($grant);
}

/**
* @expectedException League\OAuth2\Client\Grant\Exception\InvalidGrantException
* @expectedException \League\OAuth2\Client\Grant\Exception\InvalidGrantException
*/
public function testCheckGrantInvalidFails()
{
Expand Down
2 changes: 1 addition & 1 deletion test/src/Grant/GrantTestCase.php
Expand Up @@ -41,7 +41,7 @@ abstract public function providerGetAccessToken();
/**
* Callback to test access token request parameters.
*
* @return Closure
* @return \Closure
*/
abstract protected function getParamExpectation();

Expand Down
57 changes: 57 additions & 0 deletions test/src/PHPStan/LiberatedMethod.php
@@ -0,0 +1,57 @@
<?php
declare(strict_types = 1);

namespace League\OAuth2\Client\Test\PHPStan;

use PHPStan\Reflection\ClassMemberReflection;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;

final class LiberatedMethod implements MethodReflection
{
/** @var \PHPStan\Reflection\MethodReflection */
private $reflection;

public function __construct(MethodReflection $reflection)
{
$this->reflection = $reflection;
}

public function getDeclaringClass(): ClassReflection
{
return $this->reflection->getDeclaringClass();
}

public function isStatic(): bool
{
return $this->reflection->isStatic();
}

public function isPrivate(): bool
{
return false;
}

public function isPublic(): bool
{
return true;
}

public function getName(): string
{
return $this->reflection->getName();
}

public function getPrototype(): ClassMemberReflection
{
return $this->reflection->getPrototype();
}

/**
* @return \PHPStan\Reflection\ParametersAcceptor[]
*/
public function getVariants(): array
{
return $this->reflection->getVariants();
}
}
16 changes: 16 additions & 0 deletions test/src/PHPStan/LiberatedType.php
@@ -0,0 +1,16 @@
<?php
declare(strict_types = 1);

namespace League\OAuth2\Client\Test\PHPStan;

use PHPStan\Reflection\ClassMemberAccessAnswerer;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\ObjectType;

final class LiberatedType extends ObjectType
{
public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): MethodReflection
{
return new LiberatedMethod(parent::getMethod($methodName, $scope));
}
}
39 changes: 39 additions & 0 deletions test/src/PHPStan/LiberatorExtension.php
@@ -0,0 +1,39 @@
<?php
declare(strict_types = 1);

namespace League\OAuth2\Client\Test\PHPStan;

use Eloquent\Liberator\Liberator;
use Eloquent\Pops\ProxyInterface;
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;

final class LiberatorExtension implements DynamicStaticMethodReturnTypeExtension
{
public function getClass(): string
{
return Liberator::class;
}

public function isStaticMethodSupported(MethodReflection $methodReflection): bool
{
return $methodReflection->getName() === 'liberate';
}

public function getTypeFromStaticMethodCall(
MethodReflection $methodReflection,
StaticCall $methodCall,
Scope $scope
): Type {
$types = [new ObjectType(ProxyInterface::class)];
foreach ($scope->getType($methodCall->args[0]->value)->getReferencedClasses() as $class) {
$types[] = new LiberatedType($class);
}
return TypeCombinator::intersect(...$types);
}
}
23 changes: 12 additions & 11 deletions test/src/Provider/AbstractProviderTest.php
Expand Up @@ -2,6 +2,7 @@

namespace League\OAuth2\Client\Test\Provider;

use League\OAuth2\Client\Token\ResourceOwnerAccessTokenInterface;
use UnexpectedValueException;
use Eloquent\Liberator\Liberator;
use Eloquent\Phony\Phpunit\Phony;
Expand All @@ -13,7 +14,6 @@
use League\OAuth2\Client\Grant\GrantFactory;
use League\OAuth2\Client\Grant\Exception\InvalidGrantException;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Token\AccessTokenInterface;
use League\OAuth2\Client\Tool\RequestFactory;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -46,7 +46,7 @@ public function testInvalidGrantString()
public function testInvalidGrantObject()
{
$this->expectException(InvalidGrantException::class);
$grant = new \StdClass();
$grant = new \stdClass();
$this->provider->getAccessToken($grant, ['invalid_parameter' => 'none']);
}

Expand Down Expand Up @@ -161,18 +161,18 @@ public function testConstructorSetsRequestFactory()

public function testSetRedirectHandler()
{
$this->testFunction = false;
$this->state = false;
$testFunction = false;
$state = false;

$callback = function ($url, $provider) {
$this->testFunction = $url;
$this->state = $provider->getState();
$callback = function ($url, $provider) use (&$testFunction, &$state) {
$testFunction = $url;
$state = $provider->getState();
};

$this->provider->authorize([], $callback);

$this->assertNotFalse($this->testFunction);
$this->assertAttributeEquals($this->state, 'state', $this->provider);
$this->assertNotFalse($testFunction);
$this->assertAttributeEquals($state, 'state', $this->provider);
}

/**
Expand Down Expand Up @@ -201,6 +201,7 @@ public function testGetUserProperties($response, $name = null, $email = null, $i

// Run
$provider->setHttpClient($client->get());
/** @var \League\OAuth2\Client\Test\Provider\Fake\User $user */
$user = $provider->getResourceOwner($token);
$url = $provider->getResourceOwnerDetailsUrl($token);

Expand Down Expand Up @@ -299,7 +300,6 @@ public function getHeadersTest()
$this->assertEquals([], $provider->getHeaders());
$this->assertEquals([], $provider->getHeaders('mock_token'));

$provider->authorizationHeader = 'Bearer';
$this->assertEquals(['Authorization' => 'Bearer abc'], $provider->getHeaders('abc'));

$token = new AccessToken(['access_token' => 'xyz', 'expires_in' => 3600]);
Expand Down Expand Up @@ -366,6 +366,7 @@ public function testErrorResponsesCanBeCustomizedAtTheProvider()

$errorMessage = '';
$errorCode = 0;
$errorBody = [];

try {
$provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']);
Expand Down Expand Up @@ -525,7 +526,7 @@ public function testGetAccessToken($method)
$token = $provider->getAccessToken($grant->get(), ['code' => 'mock_authorization_code']);

// Verify
$this->assertInstanceOf(AccessTokenInterface::class, $token);
$this->assertInstanceOf(ResourceOwnerAccessTokenInterface::class, $token);

$this->assertSame($raw_response['resource_owner_id'], $token->getResourceOwnerId());
$this->assertSame($raw_response['access_token'], $token->getToken());
Expand Down
Expand Up @@ -22,16 +22,6 @@ protected function setUp()
$this->exception = new IdentityProviderException($this->result['error'], $this->result['code'], $this->result);
}

public function testGetType()
{
$this->assertEquals('Exception', $this->exception->getType());
}

public function testAsString()
{
$this->assertEquals('Exception: 404: message', (string)$this->exception);
}

public function testGetResponseBody()
{

Expand Down
4 changes: 2 additions & 2 deletions test/src/Provider/Generic.php
Expand Up @@ -7,7 +7,7 @@

class Generic extends GenericProvider
{
public function __construct($options = [], array $collaborators = [])
public function __construct($options = [])
{
// Add the required defaults for AbstractProvider
$options += [
Expand All @@ -16,7 +16,7 @@ public function __construct($options = [], array $collaborators = [])
'redirectUri' => 'none',
];

parent::__construct($options);
parent::__construct($options, []);
}

protected function fetchResourceOwnerDetails(AccessToken $token)
Expand Down
4 changes: 4 additions & 0 deletions test/src/Tool/ProviderRedirectTraitTest.php
Expand Up @@ -5,6 +5,7 @@
use Eloquent\Phony\Phpunit\Phony;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\BadResponseException;
use InvalidArgumentException;
use League\OAuth2\Client\Tool\ProviderRedirectTrait;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -14,6 +15,9 @@ class ProviderRedirectTraitTest extends TestCase
{
use ProviderRedirectTrait;

/** @var \GuzzleHttp\ClientInterface|null */
private $httpClient;

public function getHttpClient()
{
return $this->httpClient;
Expand Down

0 comments on commit dab158e

Please sign in to comment.