Removing Dependency from SDK Core Project

- Copied files required for Rest API SDK
- Removed PPApiContext and directly connected APIContext with PPConfigManager
- Removed duplicate data storage of configuration and credentials.
- Code Style Fixes
- Remove build.xml file as it is not required anymore
- Updated the samples
- Updated the documentations
This commit is contained in:
japatel
2014-10-06 11:16:47 -05:00
parent bb7654b0b8
commit 49b80f76af
150 changed files with 10975 additions and 6525 deletions

View File

@@ -0,0 +1,126 @@
<?php
use PayPal\Core\PPConfigManager;
/**
* Test class for PPConfigManager.
* @preserveGlobalState disabled
* @runTestsInSeparateProcesses
*/
class PPConfigManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PPConfigManager
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$loader = require dirname(__DIR__) . '/../../../vendor/autoload.php';
$loader->add('PayPal\\Test', __DIR__);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
*/
public function testGetInstance()
{
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__))));
$this->object = PPConfigManager::getInstance();
$instance = $this->object->getInstance();
$instance2 = $this->object->getInstance();
$this->assertTrue($instance instanceof PPConfigManager);
$this->assertSame($instance, $instance2);
}
/**
* @test
*/
public function testGet()
{
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__))));
$this->object = PPConfigManager::getInstance();
$ret = $this->object->get('acct2');
$this->assertConfiguration(['acct2.ClientId' => 'TestClientId', 'acct2.ClientSecret' => 'TestClientSecret'], $ret);
$this->assertTrue(sizeof($ret) == 2);
}
/**
* @test
*/
public function testGetIniPrefix()
{
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__))));
$this->object = PPConfigManager::getInstance();
$ret = $this->object->getIniPrefix();
$this->assertContains('acct1', $ret);
$this->assertEquals(sizeof($ret), 2);
$ret = $this->object->getIniPrefix('TestClientId');
$this->assertEquals('acct2', $ret);
}
/**
* @test
*/
public function testConfigByDefault()
{
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__))));
$this->object = PPConfigManager::getInstance();
// Test file based config params and defaults
$config = PPConfigManager::getInstance()->getConfigHashmap();
$this->assertConfiguration(['mode' => 'sandbox', 'http.ConnectionTimeOut' => '60'], $config);
}
public function testConfigByCustom()
{
define("PP_CONFIG_PATH", dirname(dirname(dirname(__DIR__))));
$this->object = PPConfigManager::getInstance();
// Test custom config params and defaults
$config = PPConfigManager::getInstance()->addConfigs(['mode' => 'custom', 'http.ConnectionTimeOut' => 900])->getConfigHashmap();
$this->assertConfiguration(['mode' => 'custom', 'http.ConnectionTimeOut' => '900'], $config);
}
public function testConfigByFileAndCustom() {
define("PP_CONFIG_PATH", __DIR__. '/non_existent/');
$this->object = PPConfigManager::getInstance();
$config = PPConfigManager::getInstance()->getConfigHashmap();
$this->assertArrayHasKey('http.ConnectionTimeOut', $config);
$this->assertEquals('30', $config['http.ConnectionTimeOut']);
$this->assertEquals('5', $config['http.Retry']);
//Add more configs
$config = PPConfigManager::getInstance()->addConfigs(['http.Retry' => "10", 'mode' => 'sandbox'])->getConfigHashmap();
$this->assertConfiguration(['http.ConnectionTimeOut' => "30", 'http.Retry' => "10", 'mode' => 'sandbox'], $config);
}
/**
* Asserts if each configuration is available and has expected value.
*
* @param $conditions
* @param $config
*/
public function assertConfiguration($conditions, $config) {
foreach($conditions as $key => $value) {
$this->assertArrayHasKey($key, $config);
$this->assertEquals($value, $config[$key]);
}
}
}
?>

View File

@@ -0,0 +1,145 @@
<?php
use PayPal\Core\PPCredentialManager;
/**
* Test class for PPCredentialManager.
*
* @runTestsInSeparateProcesses
*/
class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PPCredentialManager
*/
protected $object;
private $config = array(
'acct1.ClientId' => 'client-id',
'acct1.ClientSecret' => 'client-secret',
'http.ConnectionTimeOut' => '30',
'http.Retry' => '5',
'service.RedirectURL' => 'https://www.sandbox.paypal.com/webscr&cmd=',
'service.DevCentralURL' => 'https://developer.paypal.com',
'service.EndPoint.IPN' => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
'service.EndPoint.AdaptivePayments' => 'https://svcs.sandbox.paypal.com/',
'service.SandboxEmailAddress' => 'platform_sdk_seller@gmail.com',
'log.FileName' => 'PayPal.log',
'log.LogLevel' => 'INFO',
'log.LogEnabled' => '1',
);
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = PPCredentialManager::getInstance($this->config);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
*/
public function testGetInstance()
{
$instance = $this->object->getInstance($this->config);
$this->assertTrue($instance instanceof PPCredentialManager);
}
/**
* @test
*/
public function testGetSpecificCredentialObject()
{
$cred = $this->object->getCredentialObject('acct1');
$this->assertNotNull($cred);
$this->assertAttributeEquals('client-id', 'clientId', $cred);
$this->assertAttributeEquals('client-secret', 'clientSecret', $cred);
}
/**
* @after testGetDefaultCredentialObject
*
* @throws \PayPal\Exception\PPInvalidCredentialException
*/
public function testSetCredentialObject() {
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
->disableOriginalConstructor()
->getMock();
$cred = $this->object->setCredentialObject($authObject)->getCredentialObject();
$this->assertNotNull($cred);
$this->assertSame($this->object->getCredentialObject(), $authObject);
}
/**
* @after testGetDefaultCredentialObject
*
* @throws \PayPal\Exception\PPInvalidCredentialException
*/
public function testSetCredentialObjectWithUserId() {
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
->disableOriginalConstructor()
->getMock();
$cred = $this->object->setCredentialObject($authObject, 'sample')->getCredentialObject('sample');
$this->assertNotNull($cred);
$this->assertSame($this->object->getCredentialObject(), $authObject);
}
/**
* @after testGetDefaultCredentialObject
*
* @throws \PayPal\Exception\PPInvalidCredentialException
*/
public function testSetCredentialObjectWithoutDefault() {
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
->disableOriginalConstructor()
->getMock();
$cred = $this->object->setCredentialObject($authObject, null, false)->getCredentialObject();
$this->assertNotNull($cred);
$this->assertNotSame($this->object->getCredentialObject(), $authObject);
}
/**
* @test
*/
public function testGetInvalidCredentialObject()
{
$this->setExpectedException('PayPal\Exception\PPInvalidCredentialException');
$cred = $this->object->getCredentialObject('invalid_biz_api1.gmail.com');
}
/**
*
*/
public function testGetDefaultCredentialObject()
{
$cred = $this->object->getCredentialObject();
$this->assertNotNull($cred);
$this->assertAttributeEquals('client-id', 'clientId', $cred);
$this->assertAttributeEquals('client-secret', 'clientSecret', $cred);
}
/**
* @test
*/
public function testGetRestCredentialObject() {
$cred = $this->object->getCredentialObject('acct1');
$this->assertNotNull($cred);
$this->assertAttributeEquals($this->config['acct1.ClientId'], 'clientId', $cred);
$this->assertAttributeEquals($this->config['acct1.ClientSecret'], 'clientSecret', $cred);
}
}
?>

View File

@@ -0,0 +1,121 @@
<?php
use PayPal\Core\PPHttpConfig;
/**
* Test class for PPAPIService.
*
*/
class PPHttpConfigTest extends PHPUnit_Framework_TestCase
{
protected $object;
private $config = array(
'http.ConnectionTimeOut' => '30',
'http.Retry' => '5' ,
);
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
*/
public function testHeaderFunctions()
{
$o = new PPHttpConfig();
$o->addHeader('key1', 'value1');
$o->addHeader('key2', 'value');
$o->addHeader('key2', 'overwritten');
$this->assertEquals(2, count($o->getHeaders()));
$this->assertEquals('overwritten', $o->getHeader('key2'));
$this->assertNull($o->getHeader('key3'));
$o = new PPHttpConfig();
$o->addHeader('key1', 'value1');
$o->addHeader('key2', 'value');
$o->addHeader('key2', 'and more', false);
$this->assertEquals(2, count($o->getHeaders()));
$this->assertEquals('value;and more', $o->getHeader('key2'));
$o->removeHeader('key2');
$this->assertEquals(1, count($o->getHeaders()));
$this->assertNull($o->getHeader('key2'));
}
/**
* @test
*/
public function testCurlOpts()
{
$o = new PPHttpConfig();
$o->setCurlOptions(array('k' => 'v'));
$curlOpts = $o->getCurlOptions();
$this->assertEquals(1, count($curlOpts));
$this->assertEquals('v', $curlOpts['k']);
}
/**
* @test
*/
public function testUserAgent()
{
$ua = 'UAString';
$o = new PPHttpConfig();
$o->setUserAgent($ua);
$curlOpts= $o->getCurlOptions();
$this->assertEquals($ua, $curlOpts[CURLOPT_USERAGENT]);
}
/**
* @test
*/
public function testSSLOpts()
{
$sslCert = '../cacert.pem';
$sslPass = 'passPhrase';
$o = new PPHttpConfig();
$o->setSSLCert($sslCert, $sslPass);
$curlOpts= $o->getCurlOptions();
$this->assertArrayHasKey(CURLOPT_SSLCERT, $curlOpts);
$this->assertEquals($sslPass, $curlOpts[CURLOPT_SSLCERTPASSWD]);
}
/**
* @test
*/
public function testProxyOpts()
{
$proxy = 'http://me:secret@hostname:8081';
$o = new PPHttpConfig();
$o->setHttpProxy($proxy);
$curlOpts= $o->getCurlOptions();
$this->assertEquals('hostname:8081', $curlOpts[CURLOPT_PROXY]);
$this->assertEquals('me:secret', $curlOpts[CURLOPT_PROXYUSERPWD]);
$this->setExpectedException('PayPal\Exception\PPConfigurationException');
$o->setHttpProxy('invalid string');
}
}
?>

View File

@@ -0,0 +1,64 @@
<?php
use PayPal\Core\PPLoggingManager;
/**
* Test class for PPLoggingManager.
*
*/
class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PPLoggingManager
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new PPLoggingManager('InvoiceTest');
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @test
*/
public function testError()
{
$this->object->error('Test Error Message');
}
/**
* @test
*/
public function testWarning()
{
$this->object->warning('Test Warning Message');
}
/**
* @test
*/
public function testInfo()
{
$this->object->info('Test info Message');
}
/**
* @test
*/
public function testFine()
{
$this->object->fine('Test fine Message');
}
}
?>