Setup base unit testing framework

1.0
Tom Anderson 2014-04-23 23:13:25 -07:00
parent 6387ae33fe
commit 4ce38514ae
7 changed files with 108 additions and 16 deletions

11
.gitignore vendored
View File

@ -1,5 +1,8 @@
/vendor/
/composer.lock
vendor/
composer.lock
composer.phar
.DS_Store
/testing/
/nbproject/private/
testing/
nbproject/private/
test/log
build

View File

@ -9,7 +9,7 @@
"require-dev": {
"phpunit/phpunit": "*",
"fabpot/php-cs-fixer": "0.4.*@dev",
"fzaninotto/faker": "*"
"mockery/mockery": "dev-master"
},
"keywords": [
"oauth",

View File

@ -2,22 +2,20 @@
<phpunit colors="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" bootstrap="tests/Bootstrap.php">
<testsuites>
<testsuite name="OAuth Client">
<directory suffix="Test.php">tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">PEAR_INSTALL_DIR</directory>
<directory suffix=".php">PHP_LIBDIR</directory>
<directory suffix=".php">vendor/composer</directory>
<directory suffix=".php">vendor/phpunit</directory>
<directory suffix=".php">vendor</directory>
<directory suffix=".php">tests</directory>
<directory suffix=".php">build</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-html" target="coverage" title="lncd/OAuth-client" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="90"/>
<log type="coverage-html" target="build/log/coverage" title="lncd/OAuth-client" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="90"/>
<log type="coverage-text" target="php://stdout" title="lncd/OAuth-client" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="90"/>
<log type="coverage-clover" target="logs/clover.xml"/>
<log type="junit" target="logs/junit.xml" logIncompleteSkipped="false"/>
<log type="coverage-clover" target="build/log/clover.xml"/>
<log type="junit" target="build/log/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>

View File

@ -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,

View File

@ -1,5 +1,43 @@
<?php
if ( ! @include_once __DIR__ . '/../vendor/autoload.php') {
exit("You must set up the project dependencies, run the following commands:\n> 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();

View File

View File

@ -0,0 +1,54 @@
<?php
namespace LeagueTest\OAuth2\Client\Provider;
use \Mockery as m;
use Zend\Uri\UriFactory;
class GithubTest extends \PHPUnit_Framework_TestCase
{
protected $provider;
protected function setUp()
{
$this->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'));
}
*/
}