provider = new \League\OAuth2\Client\Provider\Google([ 'clientId' => 'mock_client_id', 'clientSecret' => 'mock_secret', 'redirectUri' => 'none', ]); } public function tearDown() { m::close(); parent::tearDown(); } /** * @expectedException InvalidArgumentException */ public function testInvalidGrantString() { $this->provider->getAccessToken('invalid_grant', ['invalid_parameter' => 'none']); } /** * @expectedException InvalidArgumentException */ public function testInvalidGrantObject() { $grant = new \StdClass(); $this->provider->getAccessToken($grant, ['invalid_parameter' => 'none']); } public function testAuthorizationUrlStateParam() { $this->assertContains('state=XXX', $this->provider->getAuthorizationUrl([ 'state' => 'XXX' ])); } /** * 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}); } } public function testSetRedirectHandler() { $this->testFunction = false; $callback = function ($url) { $this->testFunction = $url; }; $this->provider->setRedirectHandler($callback); $this->provider->authorize('http://test.url/'); $this->assertNotFalse($this->testFunction); } } 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 ''; } }