From 4ce38514ae54ac6f90868a35514c36558770fa66 Mon Sep 17 00:00:00 2001 From: Tom Anderson Date: Wed, 23 Apr 2014 23:13:25 -0700 Subject: [PATCH] Setup base unit testing framework --- .gitignore | 11 ++++--- composer.json | 2 +- phpunit.xml | 14 ++++---- src/Provider/IdentityProvider.php | 1 - tests/Bootstrap.php | 42 ++++++++++++++++++++++-- tests/ProviderTest.php | 0 tests/src/Provider/GithubTest.php | 54 +++++++++++++++++++++++++++++++ 7 files changed, 108 insertions(+), 16 deletions(-) delete mode 100644 tests/ProviderTest.php create mode 100644 tests/src/Provider/GithubTest.php diff --git a/.gitignore b/.gitignore index 09bbf57..8ef0567 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ -/vendor/ -/composer.lock +vendor/ +composer.lock +composer.phar .DS_Store -/testing/ -/nbproject/private/ \ No newline at end of file +testing/ +nbproject/private/ +test/log +build diff --git a/composer.json b/composer.json index f9e8f76..8e6ad95 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "require-dev": { "phpunit/phpunit": "*", "fabpot/php-cs-fixer": "0.4.*@dev", - "fzaninotto/faker": "*" + "mockery/mockery": "dev-master" }, "keywords": [ "oauth", diff --git a/phpunit.xml b/phpunit.xml index 4abf1df..7940c15 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,22 +2,20 @@ - tests + tests - PEAR_INSTALL_DIR - PHP_LIBDIR - vendor/composer - vendor/phpunit + vendor tests + build - + - - + + diff --git a/src/Provider/IdentityProvider.php b/src/Provider/IdentityProvider.php index ccd1e84..c0ae7a4 100644 --- a/src/Provider/IdentityProvider.php +++ b/src/Provider/IdentityProvider.php @@ -64,7 +64,6 @@ abstract class IdentityProvider public function getAuthorizationUrl($options = array()) { $state = md5(uniqid(rand(), true)); - setcookie($this->name.'_authorize_state', $state); $params = array( 'client_id' => $this->clientId, diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index a0e4735..ae080ab 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -1,5 +1,43 @@ wget http://getcomposer.org/composer.phar\n> php composer.phar install\n"); +namespace LeagueTests\OAuth2\Client; + +error_reporting(E_ALL | E_STRICT); +chdir(__DIR__); + +/** + * Test bootstrap, for setting up autoloading + * + * @subpackage UnitTest + */ +class Bootstrap +{ + protected static $serviceManager; + + public static function init() + { + static::initAutoloader(); + } + + protected static function initAutoloader() + { + $vendorPath = static::findParentPath('vendor'); + + $loader = include $vendorPath . '/autoload.php'; + } + + protected static function findParentPath($path) + { + $dir = __DIR__; + $previousDir = '.'; + while (!is_dir($dir . '/' . $path)) { + $dir = dirname($dir); + if ($previousDir === $dir) return false; + $previousDir = $dir; + } + + return $dir . '/' . $path; + } } + +Bootstrap::init(); diff --git a/tests/ProviderTest.php b/tests/ProviderTest.php deleted file mode 100644 index e69de29..0000000 diff --git a/tests/src/Provider/GithubTest.php b/tests/src/Provider/GithubTest.php new file mode 100644 index 0000000..350bcc3 --- /dev/null +++ b/tests/src/Provider/GithubTest.php @@ -0,0 +1,54 @@ +provider = new \League\OAuth2\Client\Provider\Github(array( + 'clientId' => 'mock', + 'clientSecret' => 'mock_secret', + 'redirectUri' => 'none', + )); + } + + protected function tearDown() + { +# m::close(); + } + + public function testAuthorizationUrl() + { + $url = $this->provider->getAuthorizationUrl(); + $uri = parse_url($url); + parse_str($uri['query'], $query); + + $this->assertArrayHasKey('client_id', $query); + $this->assertArrayHasKey('redirect_uri', $query); + $this->assertArrayHasKey('state', $query); + $this->assertArrayHasKey('scope', $query); + $this->assertArrayHasKey('response_type', $query); + $this->assertArrayHasKey('approval_prompt', $query); + } + + public function testUrlAccessToken() + { + $url = $this->provider->urlAccessToken(); + $uri = parse_url($url); + + $this->assertEquals('/login/oauth/access_token', $uri['path']); + } + +/* + public function testGetAccessToken() + { + $t = $this->provider->getAccessToken('authorization_code', array('code' => 'mock_authorization_code')); + } +*/ +}