diff --git a/composer.json b/composer.json index 8cf7899..7cd1b60 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "monolog/monolog": "1.13.*" }, "require-dev": { + "mockery/mockery": "dev-master", "satooshi/php-coveralls": "dev-master" }, "autoload": { diff --git a/examples/config.php b/examples/config.php index aed2340..eedb6bd 100644 --- a/examples/config.php +++ b/examples/config.php @@ -9,6 +9,10 @@ 'key' => '', 'secret' => '', ], + 'weibo' => [ + 'key' => '', + 'secret' => '', + ], 'hundsun' => [ 'key' => '', 'secret' => '' diff --git a/examples/service.php b/examples/service.php index cca4e9b..cd28317 100644 --- a/examples/service.php +++ b/examples/service.php @@ -17,3 +17,5 @@ 'callback' => dirname('http://' . $_SERVER['SERVER_NAME'] . $_SERVER["REQUEST_URI"]) . '/access.php?provider=' . $provider ]); +$service->debug(); +$service->setLogPath(__DIR__ . '/../tmp/access.log'); diff --git a/src/EvaOAuth/OAuth2/Providers/Weibo.php b/src/EvaOAuth/OAuth2/Providers/Weibo.php new file mode 100644 index 0000000..7c0c059 --- /dev/null +++ b/src/EvaOAuth/OAuth2/Providers/Weibo.php @@ -0,0 +1,32 @@ + 'Eva\EvaOAuth\OAuth1\Providers\Twitter', 'douban' => 'Eva\EvaOAuth\OAuth2\Providers\Douban', 'tencent' => 'Eva\EvaOAuth\OAuth2\Providers\Tencent', + 'weibo' => 'Eva\EvaOAuth\OAuth2\Providers\Weibo', 'hundsun' => 'Eva\EvaOAuth\OAuth2\Providers\Hundsun', ]; @@ -83,6 +84,22 @@ public static function registerProviders(array $classes) } } + /** + * @return array + */ + public static function getProviders() + { + return self::$providers; + } + + /** + * @return OAuth1Provider|OAuth2Provider + */ + public function getProvider() + { + return $this->provider; + } + /** * @return Consumer|Client */ @@ -144,6 +161,18 @@ public function setLogPath($logPath) return $this; } + /** + * Enable debug mode + * Guzzle will print all request and response on screen + * @return $this + */ + public function debug() + { + $adapter = $this->getAdapter(); + $adapter::getHttpClient()->getEmitter()->attach(new LogSubscriber(og, Formatter::DEBUG)); + return $this; + } + /** * @param string $providerName * @param array $options diff --git a/tests/EvaOAuthTest/ServiceTest.php b/tests/EvaOAuthTest/ServiceTest.php new file mode 100644 index 0000000..47b1fd5 --- /dev/null +++ b/tests/EvaOAuthTest/ServiceTest.php @@ -0,0 +1,73 @@ + 'test_key', + 'secret' => 'test_secret', + 'callback' => 'test_callback', + ]); + $this->assertInstanceOf('Eva\EvaOAuth\OAuth2\Client', $service->getAdapter()); + + $service = new Service('twitter', [ + 'key' => 'test_key', + 'secret' => 'test_secret', + 'callback' => 'test_callback', + ]); + $this->assertInstanceOf('Eva\EvaOAuth\OAuth1\Consumer', $service->getAdapter()); + } + + /** + * @expectedException Eva\EvaOAuth\Exception\InvalidArgumentException + */ + public function testProviderInterface() + { + \Mockery::namedMock('FooProvider'); + Service::registerProvider('foo', 'FooProvider'); + $service = new Service('foo', [ + 'key' => 'test_key', + 'secret' => 'test_secret', + 'callback' => 'test_callback', + ]); + } + + public function testRegisterProvider() + { + \Mockery::namedMock('FooOAuth2Provider', 'Eva\EvaOAuth\OAuth2\Providers\AbstractProvider'); + \Mockery::namedMock('BarOAuth1Provider', 'Eva\EvaOAuth\OAuth1\Providers\AbstractProvider'); + Service::registerProviders([ + 'foo' => 'FooOAuth2Provider', + 'bar' => 'BarOAuth2Provider', + ]); + $this->assertArrayHasKey('foo', Service::getProviders()); + $this->assertArrayHasKey('bar', Service::getProviders()); + + $service = new Service('foo', [ + 'key' => 'test_key', + 'secret' => 'test_secret', + 'callback' => 'test_callback', + ]); + $this->assertInstanceOf('FooOAuth2Provider', $service->getProvider()); + } +}