Updated OAuthToken to throw proper error on not receiving access token

- Updated Samples, Tests
This commit is contained in:
japatel
2015-01-13 23:57:56 -06:00
parent df00ab2602
commit baf06a66be
4 changed files with 229 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
<?php
namespace PayPal\Test\Cache;
use PayPal\Cache\AuthorizationCache;
/**
@@ -9,6 +10,7 @@ use PayPal\Cache\AuthorizationCache;
*/
class AuthorizationCacheTest extends \PHPUnit_Framework_TestCase
{
const CACHE_FILE = 'tests/var/test.cache';
/**
* Sets up the fixture, for example, opens a network connection.
@@ -16,7 +18,6 @@ class AuthorizationCacheTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
}
/**
@@ -32,17 +33,13 @@ class AuthorizationCacheTest extends \PHPUnit_Framework_TestCase
return array(
array(array('cache.enabled' => 'true'), true),
array(array('cache.enabled' => true), true),
array(array(), false),
array(null, false)
);
}
public static function CachePathProvider()
{
return array(
array(array('cache.FileName' => 'temp.cache'), 'temp.cache'),
array(array(), 'auth.cache'),
array(null, 'auth.cache')
array(array('cache.FileName' => 'temp.cache'), 'temp.cache')
);
}
@@ -65,4 +62,46 @@ class AuthorizationCacheTest extends \PHPUnit_Framework_TestCase
$this->assertContains($expected, $result);
}
public function testCacheDisabled()
{
// 'cache.enabled' => true,
AuthorizationCache::push(array('cache.enabled' => false), 'clientId', 'accessToken', 'tokenCreateTime', 'tokenExpiresIn');
AuthorizationCache::pull(array('cache.enabled' => false), 'clientId');
}
public function testCachePush()
{
AuthorizationCache::push(array('cache.enabled' => true, 'cache.FileName' => AuthorizationCacheTest::CACHE_FILE), 'clientId', 'accessToken', 'tokenCreateTime', 'tokenExpiresIn');
$contents = file_get_contents(AuthorizationCacheTest::CACHE_FILE);
$tokens = json_decode($contents, true);
$this->assertNotNull($contents);
$this->assertEquals('clientId', $tokens['clientId']['clientId']);
$this->assertEquals('accessToken', $tokens['clientId']['accessToken']);
$this->assertEquals('tokenCreateTime', $tokens['clientId']['tokenCreateTime']);
$this->assertEquals('tokenExpiresIn', $tokens['clientId']['tokenExpiresIn']);
}
public function testCachePullNonExisting()
{
$result = AuthorizationCache::pull(array('cache.enabled' => true, 'cache.FileName' => AuthorizationCacheTest::CACHE_FILE), 'clientIdUndefined');
$this->assertNull($result);
}
/**
* @depends testCachePush
*/
public function testCachePull()
{
$result = AuthorizationCache::pull(array('cache.enabled' => true, 'cache.FileName' => AuthorizationCacheTest::CACHE_FILE), 'clientId');
$this->assertNotNull($result);
$this->assertTrue(is_array($result));
$this->assertEquals('clientId', $result['clientId']);
$this->assertEquals('accessToken', $result['accessToken']);
$this->assertEquals('tokenCreateTime', $result['tokenCreateTime']);
$this->assertEquals('tokenExpiresIn', $result['tokenExpiresIn']);
unlink(AuthorizationCacheTest::CACHE_FILE);
}
}