Skip to content

Commit

Permalink
Use property_exists() instead of isset() in AbstractProvider (fixes #134
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ramsey committed Nov 28, 2014
1 parent cfa35ef commit c4c8c23
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class AbstractProvider implements ProviderInterface
public function __construct($options = [])
{
foreach ($options as $option => $value) {
if (isset($this->{$option})) {
if (property_exists($this, $option)) {
$this->{$option} = $value;
}
}
Expand Down
48 changes: 48 additions & 0 deletions test/src/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,52 @@ public function testAuthorizationUrlStateParam()
]));
}

/**
* Tests https://github.com/thephpleague/oauth2-client/issues/134
*/
public function testConstructorSetsProperties()
{
$options = [
'clientId' => '1234',
'clientSecret' => '4567',
'redirectUri' => 'http://example.org/redirect',
'state' => 'foo',
'name' => 'bar',
'uidKey' => 'mynewuid',
'scopes' => ['a', 'b', 'c'],
'method' => 'get',
'scopeSeparator' => ';',
'responseType' => 'csv',
'headers' => ['Foo' => 'Bar'],
];

$mockProvider = new MockProvider($options);

foreach ($options as $key => $value) {
$this->assertEquals($value, $mockProvider->{$key});
}
}
}

class MockProvider extends \League\OAuth2\Client\Provider\AbstractProvider
{
public function urlAuthorize()
{
return '';
}

public function urlAccessToken()
{
return '';
}

public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)
{
return '';
}

public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
{
return '';
}
}

0 comments on commit c4c8c23

Please sign in to comment.