Enabled EC Parameters support

- Updated Api to enabled EC Parameters
- Updated Tests
- Updated Logging Manager
- Added a feature to do validation on accessors.
This commit is contained in:
japatel
2014-10-09 11:30:12 -05:00
parent 459293838e
commit 61a52e4623
99 changed files with 9148 additions and 3609 deletions

View File

@@ -3,52 +3,57 @@ namespace PayPal\Test\Api;
use PayPal\Api\Address;
class AddressTest extends \PHPUnit_Framework_TestCase {
class AddressTest extends \PHPUnit_Framework_TestCase
{
/** @var Address */
private $address;
private $address;
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $type = "Billing";
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $type = "Billing";
public static function createAddress() {
$addr = new Address();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostalCode(self::$postalCode);
$addr->setCountryCode(self::$countryCode);
$addr->setPhone(self::$phone);
return $addr;
}
public function setup() {
$this->address = self::createAddress();
}
public static function createAddress()
{
$addr = new Address();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostalCode(self::$postalCode);
$addr->setCountryCode(self::$countryCode);
$addr->setPhone(self::$phone);
return $addr;
}
public function testGetterSetter() {
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostalCode());
$this->assertEquals(self::$countryCode, $this->address->getCountryCode());
$this->assertEquals(self::$phone, $this->address->getPhone());
}
public function setup()
{
$this->address = self::createAddress();
}
public function testSerializeDeserialize() {
$a1 = $this->address;
$a2 = new Address();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
public function testGetterSetter()
{
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostalCode());
$this->assertEquals(self::$countryCode, $this->address->getCountryCode());
$this->assertEquals(self::$phone, $this->address->getPhone());
}
public function testSerializeDeserialize()
{
$a1 = $this->address;
$a2 = new Address();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -5,41 +5,46 @@ namespace PayPal\Test\Api;
use PayPal\Api\Amount;
use PayPal\Test\Constants;
class AmountTest extends \PHPUnit_Framework_TestCase {
class AmountTest extends \PHPUnit_Framework_TestCase
{
private $amounts;
private $amounts;
public static $currency = "USD";
public static $total = "1.12";
public static $currency = "USD";
public static $total = "1.12";
public static function createAmount() {
$amount = new Amount();
$amount->setCurrency(self::$currency);
$amount->setTotal(self::$total);
return $amount;
}
public function setup() {
$this->amounts['partial'] = self::createAmount();
$amount = self::createAmount();
$amount->setDetails(DetailsTest::createAmountDetails());
$this->amounts['full'] = $amount;
}
public static function createAmount()
{
$amount = new Amount();
$amount->setCurrency(self::$currency);
$amount->setTotal(self::$total);
public function testGetterSetter() {
$this->assertEquals(self::$currency, $this->amounts['partial']->getCurrency());
$this->assertEquals(self::$total, $this->amounts['partial']->getTotal());
$this->assertEquals(DetailsTest::$fee, $this->amounts['full']->getDetails()->getFee());
}
public function testSerializeDeserialize() {
$a1 = $this->amounts['partial'];
$a2 = new Amount();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
return $amount;
}
public function setup()
{
$this->amounts['partial'] = self::createAmount();
$amount = self::createAmount();
$amount->setDetails(DetailsTest::createAmountDetails());
$this->amounts['full'] = $amount;
}
public function testGetterSetter()
{
$this->assertEquals(self::$currency, $this->amounts['partial']->getCurrency());
$this->assertEquals(self::$total, $this->amounts['partial']->getTotal());
$this->assertEquals(DetailsTest::$fee, $this->amounts['full']->getDetails()->getFee());
}
public function testSerializeDeserialize()
{
$a1 = $this->amounts['partial'];
$a2 = new Amount();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -4,129 +4,140 @@ namespace PayPal\Test\Api;
use PayPal\Api\Amount;
use PayPal\Api\Authorization;
use PayPal\Api\Links;
use PayPal\Api\PayerInfo;
use PayPal\Test\Constants;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Address;
use PayPal\Api\Payer;
use PayPal\Api\Capture;
use PayPal\Api\CreditCard;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
use PayPal\Exception\PPConnectionException;
class AuthorizationTest extends \PHPUnit_Framework_TestCase {
private $authorizations = array();
public static $create_time = "2013-02-28T00:00:00Z";
class AuthorizationTest extends \PHPUnit_Framework_TestCase
{
private $authorizations = array();
public static $create_time = "2013-02-28T00:00:00Z";
public static $update_time = "2013-03-28T00:00:00Z";
public static $id = "AUTH-123";
public static $state = "Created";
public static $parent_payment = "PAY-12345";
public static $id = "AUTH-123";
public static $state = "Created";
public static $parent_payment = "PAY-12345";
public static $valid_until = "2013-04-28T00:00:00Z";
public static $currency = "USD";
public static $total = "1.12";
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public static function createAuthorization() {
$authorization = new Authorization();
$authorization->setCreateTime(self::$create_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setAmount(AmountTest::createAmount());
$authorization->setLinks(array(LinksTest::createLinks()));
return $authorization;
}
public static function authorize()
{
$addr = new Address();
$addr->setLine1("3909 Witmer Road");
$addr->setLine2("Niagara Falls");
$addr->setCity("Niagara Falls");
$addr->setState("NY");
$addr->setPostalCode("14305");
$addr->setCountryCode("US");
$addr->setPhone("716-298-1822");
$card = new CreditCard();
$card->setType("visa");
$card->setNumber("4417119669820331");
$card->setExpireMonth("11");
$card->setExpireYear("2019");
$card->setCvv2("012");
$card->setFirstName("Joe");
$card->setLastName("Shopper");
$card->setBillingAddress($addr);
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array($fi));
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription("This is the payment description.");
$payment = new Payment();
$payment->setIntent("authorize");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$paymnt = $payment->create();
$resArray = $paymnt->toArray();
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
}
public function setup() {
$authorization = new Authorization();
$authorization->setCreateTime(self::$create_time);
$authorization->setUpdateTime(self::$update_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setParentPayment(self::$parent_payment);
$authorization->setValidUntil(self::$valid_until);
$this->authorizations['partial'] = $authorization;
$this->authorizations['full'] = self::createAuthorization();
}
public static $clearing_time = "2013-04-28T00:00:00Z";
public static $currency = "USD";
public static $total = "1.12";
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public function testGetterSetter() {
$authorization = $this->authorizations['partial'];
$this->assertEquals(self::$create_time, $authorization->getCreateTime());
public static function createAuthorization()
{
$authorization = new Authorization();
$authorization->setCreateTime(self::$create_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setClearingTime(self::$clearing_time);
$authorization->setAmount(AmountTest::createAmount());
$authorization->setLinks(array(LinksTest::createLinks()));
return $authorization;
}
public static function authorize()
{
$addr = new Address();
$addr->setLine1("3909 Witmer Road");
$addr->setLine2("Niagara Falls");
$addr->setCity("Niagara Falls");
$addr->setState("NY");
$addr->setPostalCode("14305");
$addr->setCountryCode("US");
$addr->setPhone("716-298-1822");
$card = new CreditCard();
$card->setType("visa");
$card->setNumber("4417119669820331");
$card->setExpireMonth("11");
$card->setExpireYear("2019");
$card->setCvv2("012");
$card->setFirstName("Joe");
$card->setLastName("Shopper");
$card->setBillingAddress($addr);
$fi = new FundingInstrument();
$fi->setCreditCard($card);
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array($fi));
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription("This is the payment description.");
$payment = new Payment();
$payment->setIntent("authorize");
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$paymnt = $payment->create();
$resArray = $paymnt->toArray();
return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
}
public function setup()
{
$authorization = new Authorization();
$authorization->setCreateTime(self::$create_time);
$authorization->setUpdateTime(self::$update_time);
$authorization->setId(self::$id);
$authorization->setState(self::$state);
$authorization->setParentPayment(self::$parent_payment);
$authorization->setValidUntil(self::$valid_until);
$authorization->setClearingTime(self::$clearing_time);
$this->authorizations['partial'] = $authorization;
$this->authorizations['full'] = self::createAuthorization();
}
public function testGetterSetter()
{
/** @var Authorization $authorization */
$authorization = $this->authorizations['partial'];
$this->assertEquals(self::$create_time, $authorization->getCreateTime());
$this->assertEquals(self::$update_time, $authorization->getUpdateTime());
$this->assertEquals(self::$id, $authorization->getId());
$this->assertEquals(self::$state, $authorization->getState());
$this->assertEquals(self::$parent_payment, $authorization->getParentPayment());
$this->assertEquals(self::$id, $authorization->getId());
$this->assertEquals(self::$state, $authorization->getState());
$this->assertEquals(self::$parent_payment, $authorization->getParentPayment());
$this->assertEquals(self::$valid_until, $authorization->getValidUntil());
$authorization = $this->authorizations['full'];
$this->assertEquals(AmountTest::$currency, $authorization->getAmount()->getCurrency());
$this->assertEquals(1, count($authorization->getLinks()));
}
public function testSerializeDeserialize() {
$a1 = $this->authorizations['partial'];
$a2 = new Authorization();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
$this->assertEquals(self::$clearing_time, $authorization->getClearingTime());
$authorization = $this->authorizations['full'];
$this->assertEquals(AmountTest::$currency, $authorization->getAmount()->getCurrency());
$this->assertEquals(1, count($authorization->getLinks()));
}
public function testSerializeDeserialize()
{
$a1 = $this->authorizations['partial'];
$a2 = new Authorization();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
/**
* @group integration
*/
public function testOperations() {
public function testOperations()
{
try {
$authId = self::authorize();
$auth = Authorization::get($authId);
@@ -141,7 +152,7 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase {
$captur->setAmount($amount);
$capt = $auth->capture($captur);
$this->assertNotNull( $capt->getId());
$this->assertNotNull($capt->getId());
$authId = self::authorize();
$auth = Authorization::get($authId);
@@ -159,25 +170,26 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase {
'Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()
);
}
}
}
/**
* @group integration
*/
public function testReauthorize() {
$authorization = Authorization::get('7GH53639GA425732B');
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$authorization->setAmount($amount);
try {
$authorization->reauthorize();
} catch (PPConnectionException $ex){
public function testReauthorize()
{
$authorization = Authorization::get('7GH53639GA425732B');
$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("1.00");
$authorization->setAmount($amount);
try {
$authorization->reauthorize();
} catch (PPConnectionException $ex) {
//var_dump($ex->getMessage());
$this->assertEquals(strpos($ex->getMessage(),"500"), false);
}
$this->assertEquals(strpos($ex->getMessage(), "500"), false);
}
$authorization->setId(null);
try {
@@ -185,5 +197,5 @@ class AuthorizationTest extends \PHPUnit_Framework_TestCase {
} catch (\InvalidArgumentException $ex) {
$this->assertEquals($ex->getMessage(), "Id cannot be null");
}
}
}
}

View File

@@ -7,60 +7,65 @@ use PayPal\Api\Authorization;
use PayPal\Api\Amount;
use PayPal\Test\Constants;
class CaptureTest extends \PHPUnit_Framework_TestCase {
class CaptureTest extends \PHPUnit_Framework_TestCase
{
private $captures;
private $captures;
public static $authorization_id = "AUTH-123";
public static $create_time = "2013-02-28T00:00:00Z";
public static $id = "C-5678";
public static $parent_payment = "PAY-123";
public static $state = "Created";
public static $authorization_id = "AUTH-123";
public static $create_time = "2013-02-28T00:00:00Z";
public static $id = "C-5678";
public static $parent_payment = "PAY-123";
public static $state = "Created";
public static function createCapture() {
$capture = new Capture();
$capture->setCreateTime(self::$create_time);
$capture->setId(self::$id);
$capture->setParentPayment(self::$parent_payment);
$capture->setState(self::$state);
return $capture;
}
public function setup() {
$this->captures['partial'] = self::createCapture();
$capture = self::createCapture();
$capture->setAmount(AmountTest::createAmount());
$capture->setLinks(array(LinksTest::createLinks()));
$this->captures['full'] = $capture;
}
public static function createCapture()
{
$capture = new Capture();
$capture->setCreateTime(self::$create_time);
$capture->setId(self::$id);
$capture->setParentPayment(self::$parent_payment);
$capture->setState(self::$state);
public function testGetterSetter() {
$this->assertEquals(self::$create_time, $this->captures['partial']->getCreateTime());
$this->assertEquals(self::$id, $this->captures['partial']->getId());
$this->assertEquals(self::$parent_payment, $this->captures['partial']->getParentPayment());
$this->assertEquals(self::$state, $this->captures['partial']->getState());
$this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency());
$links = $this->captures['full']->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$c1 = $this->captures['partial'];
$c2 = new Capture();
$c2->fromJson($c1->toJson());
$this->assertEquals($c1, $c2);
}
return $capture;
}
public function setup()
{
$this->captures['partial'] = self::createCapture();
$capture = self::createCapture();
$capture->setAmount(AmountTest::createAmount());
$capture->setLinks(array(LinksTest::createLinks()));
$this->captures['full'] = $capture;
}
public function testGetterSetter()
{
$this->assertEquals(self::$create_time, $this->captures['partial']->getCreateTime());
$this->assertEquals(self::$id, $this->captures['partial']->getId());
$this->assertEquals(self::$parent_payment, $this->captures['partial']->getParentPayment());
$this->assertEquals(self::$state, $this->captures['partial']->getState());
$this->assertEquals(AmountTest::$currency, $this->captures['full']->getAmount()->getCurrency());
$links = $this->captures['full']->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize()
{
$c1 = $this->captures['partial'];
$c2 = new Capture();
$c2->fromJson($c1->toJson());
$this->assertEquals($c1, $c2);
}
/**
* @group integration
*/
public function testOperations()
{
public function testOperations()
{
try {
$authId = AuthorizationTest::authorize();
$auth = Authorization::get($authId);
@@ -91,6 +96,6 @@ class CaptureTest extends \PHPUnit_Framework_TestCase {
'Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()
);
}
}
}
}

View File

@@ -7,66 +7,70 @@ use PayPal\Api\Address;
use PayPal\Api\CreditCard;
use PayPal\Test\Constants;
class CreditCardHistoryTest extends \PHPUnit_Framework_TestCase {
private $cards;
public static $id = "id";
public static $validUntil = "2013-02-28T00:00:00Z";
public static $state = "created";
public static $payerId = "payer-id";
public static $cardType = "visa";
public static $cardNumber = "4417119669820331";
public static $expireMonth = 11;
public static $expireYear = "2019";
public static $cvv = "012";
public static $firstName = "V";
public static $lastName = "C";
public static function createCreditCard() {
$card = new CreditCard();
$card->setType(self::$cardType);
$card->setNumber(self::$cardNumber);
$card->setExpireMonth(self::$expireMonth);
$card->setExpireYear(self::$expireYear);
$card->setCvv2(self::$cvv);
$card->setFirstName(self::$firstName);
$card->setLastName(self::$lastName);
$card->setId(self::$id);
$card->setValidUntil(self::$validUntil);
$card->setState(self::$state);
$card->setPayerId(self::$payerId);
return $card;
}
public function setup() {
$card = self::createCreditCard();
$card->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
public function testGetterSetters() {
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$this->assertEquals(2, count($cardHistory->getCreditCards()));
}
class CreditCardHistoryTest extends \PHPUnit_Framework_TestCase
{
public function testSerializationDeserialization() {
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$cardHistoryCopy = new CreditCardHistory();
$cardHistoryCopy->fromJson($cardHistory->toJSON());
$this->assertEquals($cardHistory, $cardHistoryCopy);
}
private $cards;
public static $id = "id";
public static $validUntil = "2013-02-28T00:00:00Z";
public static $state = "created";
public static $payerId = "payer-id";
public static $cardType = "visa";
public static $cardNumber = "4417119669820331";
public static $expireMonth = 11;
public static $expireYear = "2019";
public static $cvv = "012";
public static $firstName = "V";
public static $lastName = "C";
public static function createCreditCard()
{
$card = new CreditCard();
$card->setType(self::$cardType);
$card->setNumber(self::$cardNumber);
$card->setExpireMonth(self::$expireMonth);
$card->setExpireYear(self::$expireYear);
$card->setCvv2(self::$cvv);
$card->setFirstName(self::$firstName);
$card->setLastName(self::$lastName);
$card->setId(self::$id);
$card->setValidUntil(self::$validUntil);
$card->setState(self::$state);
return $card;
}
public function setup()
{
$card = self::createCreditCard();
$card->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
public function testGetterSetters()
{
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$this->assertEquals(2, count($cardHistory->getCreditCards()));
}
public function testSerializationDeserialization()
{
$cardHistory = new CreditCardHistory();
$cardHistory->setCreditCards(array($this->cards['partial'], $this->cards['full']));
$cardHistory->setCount(2);
$cardHistoryCopy = new CreditCardHistory();
$cardHistoryCopy->fromJson($cardHistory->toJSON());
$this->assertEquals($cardHistory, $cardHistoryCopy);
}
}

View File

@@ -3,90 +3,99 @@ namespace PayPal\Test\Api;
use PayPal\Api\Address;
use PayPal\Api\CreditCard;
use PayPal\Api\Links;
use PayPal\Test\Constants;
class CreditCardTest extends \PHPUnit_Framework_TestCase {
private $cards;
class CreditCardTest extends \PHPUnit_Framework_TestCase
{
public static $id = "id";
public static $validUntil = "2013-02-28T00:00:00Z";
public static $state = "created";
public static $payerId = "payer-id";
public static $cardType = "visa";
public static $cardNumber = "4417119669820331";
public static $expireMonth = 11;
public static $expireYear = "2019";
public static $cvv = "012";
public static $firstName = "V";
public static $lastName = "C";
private $cards;
public static function createCreditCard() {
$card = new CreditCard();
$card->setType(self::$cardType);
$card->setNumber(self::$cardNumber);
$card->setExpireMonth(self::$expireMonth);
$card->setExpireYear(self::$expireYear);
$card->setCvv2(self::$cvv);
$card->setFirstName(self::$firstName);
$card->setLastName(self::$lastName);
$card->setPayerId(self::$payerId);
return $card;
}
public static $id = "id";
public static $validUntil = "2013-02-28T00:00:00Z";
public static $state = "created";
public static $payerId = "payer-id";
public static $cardType = "visa";
public static $cardNumber = "4417119669820331";
public static $expireMonth = 11;
public static $expireYear = "2019";
public static $cvv = "012";
public static $firstName = "V";
public static $lastName = "C";
public function setup() {
public static function createCreditCard()
{
$card = new CreditCard();
$card->setType(self::$cardType);
$card->setNumber(self::$cardNumber);
$card->setExpireMonth(self::$expireMonth);
$card->setExpireYear(self::$expireYear);
$card->setCvv2(self::$cvv);
$card->setFirstName(self::$firstName);
$card->setLastName(self::$lastName);
return $card;
}
$card = self::createCreditCard();
$card->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
public function setup()
{
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
$card = self::createCreditCard();
$card->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
public function testGetterSetters() {
$c = $this->cards['partial'];
$this->assertEquals(self::$cardType, $c->getType());
$this->assertEquals(self::$cardNumber, $c->getNumber());
$this->assertEquals(self::$expireMonth, $c->getExpireMonth());
$this->assertEquals(self::$expireYear, $c->getExpireYear());
$this->assertEquals(self::$cvv, $c->getCvv2());
$this->assertEquals(self::$firstName, $c->getFirstName());
$this->assertEquals(self::$lastName, $c->getLastName());
$this->assertEquals(self::$payerId, $c->getPayerId());
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
$c = $this->cards['full'];
$this->assertEquals(AddressTest::$line1, $c->getBillingAddress()->getLine1());
$link = $c->getLinks();
$this->assertEquals(LinksTest::$href, $link[0]->getHref());
}
public function testGetterSetters()
{
/** @var CreditCard $c */
$c = $this->cards['partial'];
$this->assertEquals(self::$cardType, $c->getType());
$this->assertEquals(self::$cardNumber, $c->getNumber());
$this->assertEquals(self::$expireMonth, $c->getExpireMonth());
$this->assertEquals(self::$expireYear, $c->getExpireYear());
$this->assertEquals(self::$cvv, $c->getCvv2());
$this->assertEquals(self::$firstName, $c->getFirstName());
$this->assertEquals(self::$lastName, $c->getLastName());
public function testSerializeDeserialize() {
$c1 = $this->cards['full'];
$json = $c1->toJson();
$c = $this->cards['full'];
$this->assertEquals(AddressTest::$line1, $c->getBillingAddress()->getLine1());
/** @var Links[] $link */
$link = $c->getLinks();
$this->assertEquals(LinksTest::$href, $link[0]->getHref());
}
$c2 = new CreditCard();
$c2->fromJson($json);
public function testSerializeDeserialize()
{
/** @var CreditCard $c1 */
$c1 = $this->cards['full'];
$json = $c1->toJson();
$this->assertEquals($c1, $c2);
}
$c2 = new CreditCard();
$c2->fromJson($json);
$this->assertEquals($c1, $c2);
}
/**
* @group integration
*/
public function testOperations() {
$c1 = $this->cards['full'];
public function testOperations()
{
/** @var CreditCard $c1 */
$c1 = $this->cards['full'];
// $this->assertNull($c1->getId());
$c1->create();
$this->assertNotNull($c1->getId());
$c1->create();
$this->assertNotNull($c1->getId());
$c2 = CreditCard::get($c1->getId());
$this->assertEquals($c1->getBillingAddress(), $c2->getBillingAddress());
$this->assertGreaterThan(0, count($c2->getLinks()));
$this->assertEquals(self::$cardType, $c2->getType());
$this->assertNotNull($c2->getState());
$this->assertEquals(true, $c2->delete());
}
$c2 = CreditCard::get($c1->getId());
$this->assertEquals($c1->getBillingAddress(), $c2->getBillingAddress());
$this->assertGreaterThan(0, count($c2->getLinks()));
$this->assertEquals(self::$cardType, $c2->getType());
$this->assertNotNull($c2->getState());
$this->assertEquals(true, $c2->delete());
}
}

View File

@@ -4,35 +4,40 @@ namespace PayPal\Test\Api;
use PayPal\Api\CreditCardToken;
use PayPal\Test\Constants;
class CreditCardTokenTest extends \PHPUnit_Framework_TestCase {
class CreditCardTokenTest extends \PHPUnit_Framework_TestCase
{
private $ccToken;
private $ccToken;
public static $payerId = "PAYER-123";
public static $creditCardId = "CC-123";
public static $payerId = "PAYER-123";
public static $creditCardId = "CC-123";
public static function createCreditCardToken() {
$ccToken = new CreditCardToken();
$ccToken->setPayerId(self::$payerId);
$ccToken->setCreditCardId(self::$creditCardId);
return $ccToken;
}
public function setup() {
$this->ccToken = self::createCreditCardToken();
}
public static function createCreditCardToken()
{
$ccToken = new CreditCardToken();
$ccToken->setPayerId(self::$payerId);
$ccToken->setCreditCardId(self::$creditCardId);
return $ccToken;
}
public function testGetterSetter() {
$this->assertEquals(self::$payerId, $this->ccToken->getPayerId());
$this->assertEquals(self::$creditCardId, $this->ccToken->getCreditCardId());
}
public function testSerializeDeserialize() {
$t1 = $this->ccToken;
$t2 = new CreditCardToken();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
public function setup()
{
$this->ccToken = self::createCreditCardToken();
}
public function testGetterSetter()
{
$this->assertEquals(self::$payerId, $this->ccToken->getPayerId());
$this->assertEquals(self::$creditCardId, $this->ccToken->getCreditCardId());
}
public function testSerializeDeserialize()
{
$t1 = $this->ccToken;
$t2 = new CreditCardToken();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
}

View File

@@ -4,42 +4,47 @@ namespace PayPal\Test\Api;
use PayPal\Api\Details;
use PayPal\Test\Constants;
class DetailsTest extends \PHPUnit_Framework_TestCase {
class DetailsTest extends \PHPUnit_Framework_TestCase
{
private $amountDetails;
private $amountDetails;
public static $subtotal = "2.00";
public static $tax = "1.12";
public static $shipping = "3.15";
public static $fee = "4.99";
public static $subtotal = "2.00";
public static $tax = "1.12";
public static $shipping = "3.15";
public static $fee = "4.99";
public static function createAmountDetails() {
$amountDetails = new Details();
$amountDetails->setSubtotal(self::$subtotal);
$amountDetails->setTax(self::$tax);
$amountDetails->setShipping(self::$shipping);
$amountDetails->setFee(self::$fee);
return $amountDetails;
}
public static function createAmountDetails()
{
$amountDetails = new Details();
$amountDetails->setSubtotal(self::$subtotal);
$amountDetails->setTax(self::$tax);
$amountDetails->setShipping(self::$shipping);
$amountDetails->setFee(self::$fee);
public function setup() {
$this->amountDetails = self::createAmountDetails();
}
public function testGetterSetters() {
$this->assertEquals(self::$subtotal, $this->amountDetails->getSubtotal());
$this->assertEquals(self::$tax, $this->amountDetails->getTax());
$this->assertEquals(self::$shipping, $this->amountDetails->getShipping());
$this->assertEquals(self::$fee, $this->amountDetails->getFee());
}
public function testSerializeDeserialize() {
$a1 = $this->amountDetails;
$a2 = new Details();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
return $amountDetails;
}
public function setup()
{
$this->amountDetails = self::createAmountDetails();
}
public function testGetterSetters()
{
$this->assertEquals(self::$subtotal, $this->amountDetails->getSubtotal());
$this->assertEquals(self::$tax, $this->amountDetails->getTax());
$this->assertEquals(self::$shipping, $this->amountDetails->getShipping());
$this->assertEquals(self::$fee, $this->amountDetails->getFee());
}
public function testSerializeDeserialize()
{
$a1 = $this->amountDetails;
$a2 = new Details();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -5,32 +5,37 @@ namespace PayPal\Test\Api;
use PayPal\Api\FundingInstrument;
use PayPal\Test\Constants;
class FundingInstrumentTest extends \PHPUnit_Framework_TestCase {
class FundingInstrumentTest extends \PHPUnit_Framework_TestCase
{
private $fi;
private $fi;
public static function createFundingInstrument() {
$fi = new FundingInstrument();
$fi->setCreditCard(CreditCardTest::createCreditCard());
$fi->setCreditCardToken(CreditCardTokenTest::createCreditCardToken());
return $fi;
}
public static function createFundingInstrument()
{
$fi = new FundingInstrument();
$fi->setCreditCard(CreditCardTest::createCreditCard());
$fi->setCreditCardToken(CreditCardTokenTest::createCreditCardToken());
return $fi;
}
public function setup() {
$this->fi = self::createFundingInstrument();
}
public function setup()
{
$this->fi = self::createFundingInstrument();
}
public function testGetterSetter() {
$this->assertEquals(CreditCardTest::$cardNumber, $this->fi->getCreditCard()->getNumber());
$this->assertEquals(CreditCardTokenTest::$creditCardId,
$this->fi->getCreditCardToken()->getCreditCardId());
}
public function testGetterSetter()
{
$this->assertEquals(CreditCardTest::$cardNumber, $this->fi->getCreditCard()->getNumber());
$this->assertEquals(CreditCardTokenTest::$creditCardId,
$this->fi->getCreditCardToken()->getCreditCardId());
}
public function testSerializeDeserialize() {
$fi1 = $this->fi;
public function testSerializeDeserialize()
{
$fi1 = $this->fi;
$fi2 = new FundingInstrument();
$fi2->fromJson($fi1->toJson());
$this->assertEquals($fi1, $fi2);
}
$fi2 = new FundingInstrument();
$fi2->fromJson($fi1->toJson());
$this->assertEquals($fi1, $fi2);
}
}

View File

@@ -5,42 +5,47 @@ use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Test\Constants;
class ItemListTest extends \PHPUnit_Framework_TestCase {
private $items = array();
private static $name = "item name";
private static $price = "1.12";
private static $quantity = "10";
private static $sku = "AXVTY123";
private static $currency = "USD";
public static function createItemList() {
$item = ItemTest::createItem();
$itemList = new ItemList();
$itemList->setItems(array($item));
$itemList->setShippingAddress(ShippingAddressTest::createAddress());
return $itemList;
}
public function setup() {
$this->items = self::createItemList();
}
public function testGetterSetters() {
$items = $this->items->getItems();
$this->assertEquals(ItemTest::createItem(), $items[0]);
$this->assertEquals(ShippingAddressTest::createAddress(), $this->items->getShippingAddress());
}
public function testSerializeDeserialize() {
$itemList = new ItemList();
$itemList->fromJson($this->items->toJSON());
$this->assertEquals($itemList, $this->items);
}
class ItemListTest extends \PHPUnit_Framework_TestCase
{
private $items = array();
private static $name = "item name";
private static $price = "1.12";
private static $quantity = "10";
private static $sku = "AXVTY123";
private static $currency = "USD";
public static function createItemList()
{
$item = ItemTest::createItem();
$itemList = new ItemList();
$itemList->setItems(array($item));
$itemList->setShippingAddress(ShippingAddressTest::createAddress());
return $itemList;
}
public function setup()
{
$this->items = self::createItemList();
}
public function testGetterSetters()
{
$items = $this->items->getItems();
$this->assertEquals(ItemTest::createItem(), $items[0]);
$this->assertEquals(ShippingAddressTest::createAddress(), $this->items->getShippingAddress());
}
public function testSerializeDeserialize()
{
$itemList = new ItemList();
$itemList->fromJson($this->items->toJSON());
$this->assertEquals($itemList, $this->items);
}
}

View File

@@ -4,43 +4,49 @@ namespace PayPal\Test\Api;
use PayPal\Api\Item;
use PayPal\Test\Constants;
class ItemTest extends \PHPUnit_Framework_TestCase {
private $item;
public static $name = "item name";
public static $price = "1.12";
public static $quantity = "10";
public static $sku = "AXVTY123";
public static $currency = "USD";
public static function createItem() {
$item = new Item();
$item->setName(self::$name);
$item->setPrice(self::$price);
$item->setQuantity(self::$quantity);
$item->setSku(self::$sku);
$item->setCurrency(self::$currency);
return $item;
}
public function setup() {
$this->item = ItemTest::createItem();
}
public function testGetterSetters() {
$this->assertEquals(self::$name, $this->item->getName());
$this->assertEquals(self::$price, $this->item->getPrice());
$this->assertEquals(self::$sku, $this->item->getSku());
$this->assertEquals(self::$quantity, $this->item->getQuantity());
$this->assertEquals(self::$currency, $this->item->getCurrency());
}
public function testSerializeDeserialize() {
$item = new Item();
$item->fromJson($this->item->toJSON());
$this->assertEquals($item, $this->item);
}
class ItemTest extends \PHPUnit_Framework_TestCase
{
private $item;
public static $name = "item name";
public static $price = "1.12";
public static $quantity = "10";
public static $sku = "AXVTY123";
public static $currency = "USD";
public static function createItem()
{
$item = new Item();
$item->setName(self::$name);
$item->setPrice(self::$price);
$item->setQuantity(self::$quantity);
$item->setSku(self::$sku);
$item->setCurrency(self::$currency);
return $item;
}
public function setup()
{
$this->item = ItemTest::createItem();
}
public function testGetterSetters()
{
$this->assertEquals(self::$name, $this->item->getName());
$this->assertEquals(self::$price, $this->item->getPrice());
$this->assertEquals(self::$sku, $this->item->getSku());
$this->assertEquals(self::$quantity, $this->item->getQuantity());
$this->assertEquals(self::$currency, $this->item->getCurrency());
}
public function testSerializeDeserialize()
{
$item = new Item();
$item->fromJson($this->item->toJSON());
$this->assertEquals($item, $this->item);
}
}

View File

@@ -5,36 +5,41 @@ namespace PayPal\Test\Api;
use PayPal\Api\Links;
use PayPal\Test\Constants;
class LinksTest extends \PHPUnit_Framework_TestCase {
class LinksTest extends \PHPUnit_Framework_TestCase
{
private $links;
private $links;
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public static function createLinks() {
$links = new Links();
$links->setHref(self::$href);
$links->setRel(self::$rel);
$links->setMethod(self::$method);
return $links;
}
public function setup() {
$this->links = self::createLinks();
}
public function testGetterSetters() {
$this->assertEquals(self::$href, $this->links->getHref());
$this->assertEquals(self::$rel, $this->links->getRel());
$this->assertEquals(self::$method, $this->links->getMethod());
}
public function testSerializeDeserialize() {
$link2 = new Links();
$link2->fromJson($this->links->toJSON());
$this->assertEquals($this->links, $link2);
}
public static $href = "USD";
public static $rel = "1.12";
public static $method = "1.12";
public static function createLinks()
{
$links = new Links();
$links->setHref(self::$href);
$links->setRel(self::$rel);
$links->setMethod(self::$method);
return $links;
}
public function setup()
{
$this->links = self::createLinks();
}
public function testGetterSetters()
{
$this->assertEquals(self::$href, $this->links->getHref());
$this->assertEquals(self::$rel, $this->links->getRel());
$this->assertEquals(self::$method, $this->links->getMethod());
}
public function testSerializeDeserialize()
{
$link2 = new Links();
$link2->fromJson($this->links->toJSON());
$this->assertEquals($this->links, $link2);
}
}

View File

@@ -7,8 +7,10 @@ use PayPal\Api\Details;
use PayPal\Api\Links;
use PayPal\Test\Constants;
class OrderTest extends \PHPUnit_Framework_TestCase {
class OrderTest extends \PHPUnit_Framework_TestCase
{
/** @var Order */
private $order;
public static $id = 'O-0AA8876533760860M';
@@ -18,40 +20,35 @@ class OrderTest extends \PHPUnit_Framework_TestCase {
public static $parentPayment = 'PAY-0AL32935UM2331537KP5Y2VA';
public static $reasonCode = 'order';
public static function createOrder() {
public static function createOrder()
{
$order = new Order();
$links = LinksTest::createLinks();
$order->setId(self::$id);
$order->setCreateTime(self::$createTime);
$order->setUpdateTime(self::$updateTime);
$order->setState(self::$state);
$order->setAmount(AmountTest::createAmount());
$order->setParentPayment(self::$parentPayment);
$order->setLinks(array($links));
$order->setReasonCode(self::$reasonCode);
return $order;
}
public function setup() {
public function setup()
{
$this->order = self::createOrder();
}
public function testGetterSetter() {
public function testGetterSetter()
{
$this->assertEquals(self::$id, $this->order->getId());
$this->assertEquals(self::$createTime, $this->order->getCreateTime());
$this->assertEquals(self::$updateTime, $this->order->getUpdateTime());
$this->assertEquals(self::$state, $this->order->getState());
$this->assertEquals(AmountTest::$currency, $this->order->getAmount()->getCurrency());
$this->assertEquals(self::$parentPayment, $this->order->getParentPayment());
$links = (array)$this->order->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
$this->assertEquals(self::$reasonCode, $this->order->getReasonCode());
}
public function testSerializeDeserialize() {
public function testSerializeDeserialize()
{
$o1 = $this->order;
$o2 = new Order();

View File

@@ -5,40 +5,45 @@ namespace PayPal\Test\Api;
use PayPal\Api\Payee;
use PayPal\Test\Constants;
class PayeeTest extends \PHPUnit_Framework_TestCase {
class PayeeTest extends \PHPUnit_Framework_TestCase
{
private $payee;
private $payee;
public static $email = "test@paypal.com";
public static $merchant_id = "1XY12121";
public static $phone = "+14081234566";
public static $email = "test@paypal.com";
public static $merchant_id = "1XY12121";
public static $phone = "+14081234566";
public static function createPayee() {
$payee = new Payee();
$payee->setEmail(self::$email);
$payee->setMerchantId(self::$merchant_id);
$payee->setPhone(self::$phone);
return $payee;
}
public function setup() {
$this->payee = self::createPayee();
}
public function testGetterSetter() {
$this->assertEquals(self::$email, $this->payee->getEmail());
$this->assertEquals(self::$merchant_id, $this->payee->getMerchantId());
$this->assertEquals(self::$phone, $this->payee->getPhone());
}
public function testSerializeDeserialize() {
$p1 = $this->payee;
$p2 = new Payee();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
public static function createPayee()
{
$payee = new Payee();
$payee->setEmail(self::$email);
$payee->setMerchantId(self::$merchant_id);
$payee->setPhone(self::$phone);
return $payee;
}
public function setup()
{
$this->payee = self::createPayee();
}
public function testGetterSetter()
{
$this->assertEquals(self::$email, $this->payee->getEmail());
$this->assertEquals(self::$merchant_id, $this->payee->getMerchantId());
$this->assertEquals(self::$phone, $this->payee->getPhone());
}
public function testSerializeDeserialize()
{
$p1 = $this->payee;
$p2 = new Payee();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -4,47 +4,52 @@ namespace PayPal\Test\Api;
use PayPal\Api\PayerInfo;
use PayPal\Test\Constants;
class PayerInfoTest extends \PHPUnit_Framework_TestCase {
class PayerInfoTest extends \PHPUnit_Framework_TestCase
{
private $payerInfo;
private $payerInfo;
public static $email = "test@paypal.com";
public static $firstName = "first";
public static $lastName = "last";
public static $phone = "408-1234-5687";
public static $payerId = "PAYER-1234";
public static $email = "test@paypal.com";
public static $firstName = "first";
public static $lastName = "last";
public static $phone = "408-1234-5687";
public static $payerId = "PAYER-1234";
public static function createPayerInfo() {
$payerInfo = new PayerInfo();
$payerInfo->setEmail(self::$email);
$payerInfo->setFirstName(self::$firstName);
$payerInfo->setLastName(self::$lastName);
$payerInfo->setPhone(self::$phone);
$payerInfo->setPayerId(self::$payerId);
$payerInfo->setShippingAddress(ShippingAddressTest::createAddress());
return $payerInfo;
}
public function setup() {
$this->payerInfo = self::createPayerInfo();
}
public static function createPayerInfo()
{
$payerInfo = new PayerInfo();
$payerInfo->setEmail(self::$email);
$payerInfo->setFirstName(self::$firstName);
$payerInfo->setLastName(self::$lastName);
$payerInfo->setPhone(self::$phone);
$payerInfo->setPayerId(self::$payerId);
$payerInfo->setShippingAddress(ShippingAddressTest::createAddress());
public function testGetterSetter() {
$this->assertEquals(self::$email, $this->payerInfo->getEmail());
$this->assertEquals(self::$firstName, $this->payerInfo->getFirstName());
$this->assertEquals(self::$lastName, $this->payerInfo->getLastName());
$this->assertEquals(self::$phone, $this->payerInfo->getPhone());
$this->assertEquals(self::$payerId, $this->payerInfo->getPayerId());
$this->assertEquals(ShippingAddressTest::$line1, $this->payerInfo->getShippingAddress()->getLine1());
}
public function testSerializeDeserialize() {
$p1 = $this->payerInfo;
$p2 = new PayerInfo();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
return $payerInfo;
}
public function setup()
{
$this->payerInfo = self::createPayerInfo();
}
public function testGetterSetter()
{
$this->assertEquals(self::$email, $this->payerInfo->getEmail());
$this->assertEquals(self::$firstName, $this->payerInfo->getFirstName());
$this->assertEquals(self::$lastName, $this->payerInfo->getLastName());
$this->assertEquals(self::$phone, $this->payerInfo->getPhone());
$this->assertEquals(self::$payerId, $this->payerInfo->getPayerId());
$this->assertEquals(ShippingAddressTest::$line1, $this->payerInfo->getShippingAddress()->getLine1());
}
public function testSerializeDeserialize()
{
$p1 = $this->payerInfo;
$p2 = new PayerInfo();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -7,39 +7,44 @@ use PayPal\Api\FundingInstrument;
use PayPal\Api\Payer;
use PayPal\Test\Constants;
class PayerTest extends \PHPUnit_Framework_TestCase {
class PayerTest extends \PHPUnit_Framework_TestCase
{
private $payer;
private $payer;
private static $paymentMethod = "credit_card";
private static $paymentMethod = "credit_card";
public static function createPayer() {
$payer = new Payer();
$payer->setPaymentMethod(self::$paymentMethod);
$payer->setPayerInfo(PayerInfoTest::createPayerInfo());
$payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument()));
return $payer;
}
public function setup() {
$this->payer = self::createPayer();
}
public static function createPayer()
{
$payer = new Payer();
$payer->setPaymentMethod(self::$paymentMethod);
$payer->setPayerInfo(PayerInfoTest::createPayerInfo());
$payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument()));
public function testGetterSetter() {
$this->assertEquals(self::$paymentMethod, $this->payer->getPaymentMethod());
$this->assertEquals(PayerInfoTest::$email, $this->payer->getPayerInfo()->getEmail());
$fi = $this->payer->getFundingInstruments();
$this->assertEquals(CreditCardTokenTest::$creditCardId, $fi[0]->getCreditCardToken()->getCreditCardId());
}
public function testSerializeDeserialize() {
$p1 = $this->payer;
$p2 = new Payer();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
return $payer;
}
public function setup()
{
$this->payer = self::createPayer();
}
public function testGetterSetter()
{
$this->assertEquals(self::$paymentMethod, $this->payer->getPaymentMethod());
$this->assertEquals(PayerInfoTest::$email, $this->payer->getPayerInfo()->getEmail());
$fi = $this->payer->getFundingInstruments();
$this->assertEquals(CreditCardTokenTest::$creditCardId, $fi[0]->getCreditCardToken()->getCreditCardId());
}
public function testSerializeDeserialize()
{
$p1 = $this->payer;
$p2 = new Payer();
$p2->fromJson($p1->toJson());
$this->assertEquals($p1, $p2);
}
}

View File

@@ -5,35 +5,42 @@ namespace PayPal\Test\Api;
use PayPal\Api\PaymentHistory;
use PayPal\Test\Constants;
class PaymentHistoryTest extends \PHPUnit_Framework_TestCase {
private $history;
public static $count = "10";
public static $nextId = "11";
public static function createPaymentHistory() {
$history = new PaymentHistory();
$history->setCount(self::$count);
$history->setNextId(self::$nextId);
$history->setPayments(array(PaymentTest::createPayment()));
return $history;
}
public function setup() {
$this->history = PaymentHistoryTest::createPaymentHistory();
}
public function testGetterSetters() {
$this->assertEquals(self::$count, $this->history->getCount());
$this->assertEquals(self::$nextId, $this->history->getNextId());
}
public function testSerializeDeserialize() {
$history = new PaymentHistory();
$history->fromJson($this->history->toJSON());
$this->assertEquals($history, $this->history);
}
class PaymentHistoryTest extends \PHPUnit_Framework_TestCase
{
/** @var PaymentHistory */
private $history;
public static $count = 10;
public static $nextId = "11";
public static function createPaymentHistory()
{
$history = new PaymentHistory();
$history->setCount(self::$count);
$history->setNextId(self::$nextId);
$history->setPayments(array(PaymentTest::createPayment()));
return $history;
}
public function setup()
{
$this->history = PaymentHistoryTest::createPaymentHistory();
}
public function testGetterSetters()
{
$this->assertEquals(self::$count, $this->history->getCount());
$this->assertEquals(self::$nextId, $this->history->getNextId());
}
public function testSerializeDeserialize()
{
$history = new PaymentHistory();
$history->fromJson($this->history->toJSON());
$this->assertEquals($history, $this->history);
}
}

View File

@@ -1,5 +1,6 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Address;
use PayPal\Api\Amount;
@@ -10,76 +11,170 @@ use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
use PayPal\Test\Constants;
class PaymentTest extends \PHPUnit_Framework_TestCase {
class PaymentTest extends \PHPUnit_Framework_TestCase
{
private $payments;
private $payments;
public static function createPayment() {
public static function createPayment()
{
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer(PayerTest::createPayer());
$payment->setTransactions(array(TransactionTest::createTransaction()));
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer(PayerTest::createPayer());
$payment->setTransactions(array(TransactionTest::createTransaction()));
return $payment;
}
return $payment;
}
public static function createNewPayment() {
public static function createNewPayment()
{
$funding = FundingInstrumentTest::createFundingInstrument();
$funding->credit_card_token = null;
$funding = FundingInstrumentTest::createFundingInstrument();
$funding->credit_card_token = null;
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array($funding));
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array($funding));
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription("This is the payment description.");
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription("This is the payment description.");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://localhost/return");
$redirectUrls->setCancelUrl("http://localhost/cancel");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
return $payment;
}
return $payment;
}
public function setup() {
$this->payments['full'] = self::createPayment();
$this->payments['new'] = self::createNewPayment();
}
public function setup()
{
$this->payments['full'] = self::createPayment();
$this->payments['new'] = self::createNewPayment();
}
public function testSerializeDeserialize() {
$p2 = new Payment();
$p2->fromJson($this->payments['full']->toJSON());
$this->assertEquals($p2, $this->payments['full']);
}
public function testSerializeDeserialize()
{
$p2 = new Payment();
$p2->fromJson($this->payments['full']->toJSON());
$this->assertEquals($p2, $this->payments['full']);
}
/**
* @group integration
*/
public function testOperations() {
public function testOperations()
{
$p1 = $this->payments['new'];
$p1 = $this->payments['new'];
$p1->create();
$this->assertNotNull($p1->getId());
$p1->create();
$this->assertNotNull($p1->getId());
$p2 = Payment::get($p1->getId());
$this->assertNotNull($p2);
$p2 = Payment::get($p1->getId());
$this->assertNotNull($p2);
$paymentHistory = Payment::all(array('count' => '10'));
$this->assertNotNull($paymentHistory);
}
$paymentHistory = Payment::all(array('count' => '10'));
$this->assertNotNull($paymentHistory);
}
/**
* @group integration
*
* Tests Additional_fields, shipping_discount and insurance information.
* Additional Information: https://developer.paypal.com/docs/integration/direct/explore-payment-capabilities/
*/
public function testECParameters()
{
$json = '{
"intent": "sale",
"redirect_urls": {
"return_url": "http://www.return.com",
"cancel_url": "http://www.cancel.com"
},
"payer": {
"payment_method": "paypal",
"payer_info": {
"tax_id_type": "BR_CPF",
"tax_id": "Fh618775690"
}
},
"transactions": [
{
"amount": {
"total": "34.07",
"currency": "USD",
"details": {
"subtotal": "30.00",
"tax": "0.07",
"shipping": "1.00",
"handling_fee": "1.00",
"shipping_discount": "1.00",
"insurance": "1.00"
}
},
"description": "This is the payment transaction description.",
"custom": "EBAY_EMS_90048630024435",
"invoice_number": "48787589677",
"payment_options": {
"allowed_payment_method": "INSTANT_FUNDING_SOURCE"
},
"soft_descriptor": "ECHI5786786",
"item_list": {
"items": [
{
"name": "bowling",
"description": "Bowling Team Shirt",
"quantity": "5",
"price": "3",
"tax": "0.01",
"sku": "1",
"currency": "USD"
},
{
"name": "mesh",
"description": "80s Mesh Sleeveless Shirt",
"quantity": "1",
"price": "15",
"tax": "0.02",
"sku": "product34",
"currency": "USD"
}
],
"shipping_address": {
"recipient_name": "Betsy Buyer",
"line1": "111 First Street",
"city": "Saratoga",
"country_code": "US",
"postal_code": "95070",
"state": "CA"
}
}
}
]
}';
$payment = new Payment();
$payment->fromJson($json);
$payment->create();
$result = Payment::get($payment->getId());
$transactions = $result->getTransactions();
$transaction = $transactions[0];
$this->assertEquals($transaction->getAmount()->getDetails()->getShippingDiscount(), '1.00');
$this->assertEquals($transaction->getAmount()->getDetails()->getInsurance(), '1.00');
$this->assertEquals($transaction->getAmount()->getDetails()->getHandlingFee(), '1.00');
}
}

View File

@@ -3,40 +3,45 @@ namespace PayPal\Test\Api;
use PayPal\Api\RedirectUrls;
class RedirectUrlsTest extends \PHPUnit_Framework_TestCase {
class RedirectUrlsTest extends \PHPUnit_Framework_TestCase
{
public function validRedirectUrlsProvider() {
return array(
array('https://devtools-paypal.com/guide/pay_paypal/php?success=true', 'https://devtools-paypal.com/guide/pay_paypal/php?cancel=true')
);
}
public function validRedirectUrlsProvider()
{
return array(
array('https://devtools-paypal.com/guide/pay_paypal/php?success=true', 'https://devtools-paypal.com/guide/pay_paypal/php?cancel=true')
);
}
public function invalidRedirectUrlsProvider() {
return array(
array('devtools-paypal.com/guide/pay_paypal/php?success=true', 'devtools-paypal.com/guide/pay_paypal/php?cancel=true')
);
}
public function invalidRedirectUrlsProvider()
{
return array(
array('devtools-paypal.com/guide/pay_paypal/php?success=true', 'devtools-paypal.com/guide/pay_paypal/php?cancel=true')
);
}
/**
* @dataProvider validRedirectUrlsProvider
*/
public function testValidRedirectUrls($return_url, $cancel_url) {
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturn_url($return_url);
$redirectUrls->setCancel_url($cancel_url);
/**
* @dataProvider validRedirectUrlsProvider
*/
public function testValidRedirectUrls($return_url, $cancel_url)
{
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
$this->assertEquals($return_url, $redirectUrls->getReturnUrl());
$this->assertEquals($cancel_url, $redirectUrls->getCancelUrl());
}
$this->assertEquals($return_url, $redirectUrls->getReturnUrl());
$this->assertEquals($cancel_url, $redirectUrls->getCancelUrl());
}
/**
* @dataProvider invalidRedirectUrlsProvider
*/
public function testInvalidRedirectUrls($return_url, $cancel_url) {
$redirectUrls = new RedirectUrls();
$this->setExpectedException('\InvalidArgumentException');
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
}
/**
* @dataProvider invalidRedirectUrlsProvider
*/
public function testInvalidRedirectUrls($return_url, $cancel_url)
{
$redirectUrls = new RedirectUrls();
$this->setExpectedException('\InvalidArgumentException');
$redirectUrls->setReturnUrl($return_url);
$redirectUrls->setCancelUrl($cancel_url);
}
}

View File

@@ -4,51 +4,57 @@ namespace PayPal\Test\Api;
use PayPal\Api\Refund;
use PayPal\Test\Constants;
class RefundTest extends \PHPUnit_Framework_TestCase {
class RefundTest extends \PHPUnit_Framework_TestCase
{
private $refund;
private $refund;
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static function createRefund() {
$refund = new Refund();
public static function createRefund()
{
$refund = new Refund();
$refund->setCreateTime(self::$createTime);
$refund->setAmount(AmountTest::createAmount());
$refund->setCaptureId(self::$captureId);
$refund->setId(self::$id);
$refund->setLinks(array(LinksTest::createLinks()));
$refund->setParentPayment(self::$parentPayment);
return $refund;
}
public function setup() {
$this->refund = self::createRefund();
}
$refund->setAmount(AmountTest::createAmount());
$refund->setCaptureId(self::$captureId);
$refund->setId(self::$id);
$refund->setLinks(array(LinksTest::createLinks()));
$refund->setParentPayment(self::$parentPayment);
public function testGetterSetter() {
$this->assertEquals(self::$captureId, $this->refund->getCaptureId());
$this->assertEquals(self::$createTime, $this->refund->getCreateTime());
$this->assertEquals(self::$id, $this->refund->getId());
$this->assertEquals(self::$parentPayment, $this->refund->getParentPayment());
$this->assertEquals(AmountTest::$currency, $this->refund->getAmount()->getCurrency());
$links = $this->refund->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$r1 = $this->refund;
$r2 = new Refund();
$r2->fromJson($r1->toJson());
$this->assertEquals($r1, $r2);
}
public function testOperations() {
}
return $refund;
}
public function setup()
{
$this->refund = self::createRefund();
}
public function testGetterSetter()
{
$this->assertEquals(self::$captureId, $this->refund->getCaptureId());
$this->assertEquals(self::$createTime, $this->refund->getCreateTime());
$this->assertEquals(self::$id, $this->refund->getId());
$this->assertEquals(self::$parentPayment, $this->refund->getParentPayment());
$this->assertEquals(AmountTest::$currency, $this->refund->getAmount()->getCurrency());
$links = $this->refund->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize()
{
$r1 = $this->refund;
$r2 = new Refund();
$r2->fromJson($r1->toJson());
$this->assertEquals($r1, $r2);
}
public function testOperations()
{
}
}

View File

@@ -4,34 +4,39 @@ namespace PayPal\Test\Api;
use PayPal\Api\RelatedResources;
use PayPal\Test\Constants;
class RelatedResourcesTest extends \PHPUnit_Framework_TestCase {
class RelatedResourcesTest extends \PHPUnit_Framework_TestCase
{
private $RelatedResources;
private $RelatedResources;
public static function createRelatedResources() {
$relatedResources = new RelatedResources();
$relatedResources->setAuthorization(AuthorizationTest::createAuthorization());
$relatedResources->setCapture(CaptureTest::createCapture());
public static function createRelatedResources()
{
$relatedResources = new RelatedResources();
$relatedResources->setAuthorization(AuthorizationTest::createAuthorization());
$relatedResources->setCapture(CaptureTest::createCapture());
$relatedResources->setOrder(OrderTest::createOrder());
return $relatedResources;
}
public function setup() {
$this->relatedResources = self::createRelatedResources();
}
return $relatedResources;
}
public function testGetterSetter() {
$this->assertEquals(AuthorizationTest::$create_time, $this->relatedResources->getAuthorization()->getCreateTime());
$this->assertEquals(CaptureTest::$create_time, $this->relatedResources->getCapture()->getCreateTime());
public function setup()
{
$this->relatedResources = self::createRelatedResources();
}
public function testGetterSetter()
{
$this->assertEquals(AuthorizationTest::$create_time, $this->relatedResources->getAuthorization()->getCreateTime());
$this->assertEquals(CaptureTest::$create_time, $this->relatedResources->getCapture()->getCreateTime());
$this->assertEquals(OrderTest::$id, $this->relatedResources->getOrder()->getId());
}
public function testSerializeDeserialize() {
$s1 = $this->relatedResources;
$s2 = new RelatedResources();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
}
public function testSerializeDeserialize()
{
$s1 = $this->relatedResources;
$s2 = new RelatedResources();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
}

View File

@@ -9,54 +9,58 @@ use PayPal\Test\Api\PaymentTest;
use PayPal\Test\Api\LinksTest;
use PayPal\Exception\PPConnectionException;
class SaleTest extends \PHPUnit_Framework_TestCase {
class SaleTest extends \PHPUnit_Framework_TestCase
{
private $sale;
/** @var Sale */
private $sale;
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static $state = "Created";
public static $captureId = "CAP-123";
public static $createTime = "2013-02-28T00:00:00Z";
public static $id = "R-5678";
public static $parentPayment = "PAY-123";
public static $state = "Created";
public static function createSale() {
$sale = new Sale();
$sale->setAmount(AmountTest::createAmount());
$sale->setCreateTime(self::$createTime);
$sale->setId(self::$id);
$sale->setLinks(array(LinksTest::createLinks()));
$sale->setParentPayment(self::$parentPayment);
$sale->setState(self::$state);
return $sale;
}
public function setup() {
$this->sale = self::createSale();
}
public static function createSale()
{
$sale = new Sale();
$sale->setAmount(AmountTest::createAmount());
$sale->setCreateTime(self::$createTime);
$sale->setId(self::$id);
$sale->setParentPayment(self::$parentPayment);
$sale->setState(self::$state);
return $sale;
}
public function testGetterSetter() {
$this->assertEquals(self::$createTime, $this->sale->getCreateTime());
$this->assertEquals(self::$id, $this->sale->getId());
$this->assertEquals(self::$parentPayment, $this->sale->getParentPayment());
$this->assertEquals(self::$state, $this->sale->getState());
$this->assertEquals(AmountTest::$currency, $this->sale->getAmount()->getCurrency());
$links = $this->sale->getLinks();
$this->assertEquals(LinksTest::$href, $links[0]->getHref());
}
public function testSerializeDeserialize() {
$s1 = $this->sale;
$s2 = new Sale();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
public function setup()
{
$this->sale = self::createSale();
}
public function testGetterSetter()
{
$this->assertEquals(self::$createTime, $this->sale->getCreateTime());
$this->assertEquals(self::$id, $this->sale->getId());
$this->assertEquals(self::$parentPayment, $this->sale->getParentPayment());
$this->assertEquals(self::$state, $this->sale->getState());
$this->assertEquals(AmountTest::$currency, $this->sale->getAmount()->getCurrency());
}
public function testSerializeDeserialize()
{
$s1 = $this->sale;
$s2 = new Sale();
$s2->fromJson($s1->toJson());
$this->assertEquals($s1, $s2);
}
/**
* @group integration
*/
public function testOperations() {
public function testOperations()
{
try {
$payment = PaymentTest::createNewPayment();
$payment->create();
@@ -79,5 +83,5 @@ class SaleTest extends \PHPUnit_Framework_TestCase {
'Tests failing because of intermittent failures in Paypal Sandbox environment.' . $ex->getMessage()
);
}
}
}
}

View File

@@ -4,53 +4,58 @@ namespace PayPal\Test\Api;
use PayPal\Api\ShippingAddress;
use PayPal\Test\Constants;
class ShippingAddressTest extends \PHPUnit_Framework_TestCase {
class ShippingAddressTest extends \PHPUnit_Framework_TestCase
{
private $address;
private $address;
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $recipientName = "TestUser";
public static $line1 = "3909 Witmer Road";
public static $line2 = "Niagara Falls";
public static $city = "Niagara Falls";
public static $state = "NY";
public static $postalCode = "14305";
public static $countryCode = "US";
public static $phone = "716-298-1822";
public static $recipientName = "TestUser";
public static function createAddress() {
$addr = new ShippingAddress();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostalCode(self::$postalCode);
$addr->setCountryCode(self::$countryCode);
$addr->setPhone(self::$phone);
$addr->setRecipientName(self::$recipientName);
return $addr;
}
public function setup() {
$this->address = self::createAddress();
}
public static function createAddress()
{
$addr = new ShippingAddress();
$addr->setLine1(self::$line1);
$addr->setLine2(self::$line2);
$addr->setCity(self::$city);
$addr->setState(self::$state);
$addr->setPostalCode(self::$postalCode);
$addr->setCountryCode(self::$countryCode);
$addr->setPhone(self::$phone);
$addr->setRecipientName(self::$recipientName);
return $addr;
}
public function testGetterSetter() {
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostalCode());
$this->assertEquals(self::$countryCode, $this->address->getCountryCode());
$this->assertEquals(self::$phone, $this->address->getPhone());
$this->assertEquals(self::$recipientName, $this->address->getRecipientName());
}
public function testSerializeDeserialize() {
$a1 = $this->address;
$a2 = new ShippingAddress();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
public function setup()
{
$this->address = self::createAddress();
}
public function testGetterSetter()
{
$this->assertEquals(self::$line1, $this->address->getLine1());
$this->assertEquals(self::$line2, $this->address->getLine2());
$this->assertEquals(self::$city, $this->address->getCity());
$this->assertEquals(self::$state, $this->address->getState());
$this->assertEquals(self::$postalCode, $this->address->getPostalCode());
$this->assertEquals(self::$countryCode, $this->address->getCountryCode());
$this->assertEquals(self::$phone, $this->address->getPhone());
$this->assertEquals(self::$recipientName, $this->address->getRecipientName());
}
public function testSerializeDeserialize()
{
$a1 = $this->address;
$a2 = new ShippingAddress();
$a2->fromJson($a1->toJson());
$this->assertEquals($a1, $a2);
}
}

View File

@@ -7,52 +7,57 @@ use PayPal\Api\SubTransaction;
use PayPal\Api\Transaction;
use PayPal\Test\Constants;
class TransactionTest extends \PHPUnit_Framework_TestCase {
class TransactionTest extends \PHPUnit_Framework_TestCase
{
private $transaction;
private $transaction;
public static $description = "desc . . . ";
public static $invoiceNumber = "#123";
public static $custom = "custom";
public static $softDescriptor = "descriptor";
public static $total = "1.12";
public static $description = "desc . . . ";
public static $invoiceNumber = "#123";
public static $custom = "custom";
public static $softDescriptor = "descriptor";
public static $total = "1.12";
public static function createTransaction() {
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription(self::$description);
$transaction->setInvoiceNumber(self::$invoiceNumber);
$transaction->setCustom(self::$custom);
$transaction->setSoftDescriptor(self::$softDescriptor);
$transaction->setItemList(ItemListTest::createItemList());
$transaction->setPayee(PayeeTest::createPayee());
$transaction->setRelatedResources( array(RelatedResourcesTest::createRelatedResources()) );
return $transaction;
}
public function setup() {
$this->transaction = self::createTransaction();
}
public static function createTransaction()
{
$transaction = new Transaction();
$transaction->setAmount(AmountTest::createAmount());
$transaction->setDescription(self::$description);
$transaction->setInvoiceNumber(self::$invoiceNumber);
$transaction->setCustom(self::$custom);
$transaction->setSoftDescriptor(self::$softDescriptor);
$transaction->setItemList(ItemListTest::createItemList());
$transaction->setPayee(PayeeTest::createPayee());
$transaction->setRelatedResources(array(RelatedResourcesTest::createRelatedResources()));
return $transaction;
}
public function testGetterSetter() {
$this->assertEquals(AmountTest::$currency, $this->transaction->getAmount()->getCurrency());
$this->assertEquals(self::$description, $this->transaction->getDescription());
$this->assertEquals(self::$invoiceNumber, $this->transaction->getInvoiceNumber());
$this->assertEquals(self::$custom, $this->transaction->getCustom());
$this->assertEquals(self::$softDescriptor, $this->transaction->getSoftDescriptor());
$items = $this->transaction->getItemList()->getItems();
$this->assertEquals(ItemTest::$quantity, $items[0]->getQuantity());
$this->assertEquals(PayeeTest::$email, $this->transaction->getPayee()->getEmail());
$resources = $this->transaction->getRelatedResources();
$this->assertEquals(AuthorizationTest::$create_time, $resources[0]->getAuthorization()->getCreateTime());
}
public function testSerializeDeserialize() {
$t1 = $this->transaction;
$t2 = new Transaction();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
public function setup()
{
$this->transaction = self::createTransaction();
}
public function testGetterSetter()
{
$this->assertEquals(AmountTest::$currency, $this->transaction->getAmount()->getCurrency());
$this->assertEquals(self::$description, $this->transaction->getDescription());
$this->assertEquals(self::$invoiceNumber, $this->transaction->getInvoiceNumber());
$this->assertEquals(self::$custom, $this->transaction->getCustom());
$this->assertEquals(self::$softDescriptor, $this->transaction->getSoftDescriptor());
$items = $this->transaction->getItemList()->getItems();
$this->assertEquals(ItemTest::$quantity, $items[0]->getQuantity());
$this->assertEquals(PayeeTest::$email, $this->transaction->getPayee()->getEmail());
$resources = $this->transaction->getRelatedResources();
$this->assertEquals(AuthorizationTest::$create_time, $resources[0]->getAuthorization()->getCreateTime());
}
public function testSerializeDeserialize()
{
$t1 = $this->transaction;
$t2 = new Transaction();
$t2->fromJson($t1->toJson());
$this->assertEquals($t1, $t2);
}
}

View File

@@ -6,29 +6,33 @@ use PayPal\Auth\OAuthTokenCredential;
use PayPal\Test\Constants;
use PayPal\Core\PPConfigManager;
use PayPal\Exception\PPConnectionException;
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase {
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase
{
/**
* @group integration
*/
public function testGetAccessToken() {
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
$config = PPConfigManager::getInstance()->getConfigHashmap();
$token = $cred->getAccessToken($config);
$this->assertNotNull($token);
// Check that we get the same token when issuing a new call before token expiry
$newToken = $cred->getAccessToken($config);
$this->assertNotNull($newToken);
$this->assertEquals($token, $newToken);
}
public function testGetAccessToken()
{
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
$config = PPConfigManager::getInstance()->getConfigHashmap();
$token = $cred->getAccessToken($config);
$this->assertNotNull($token);
// Check that we get the same token when issuing a new call before token expiry
$newToken = $cred->getAccessToken($config);
$this->assertNotNull($newToken);
$this->assertEquals($token, $newToken);
}
/**
* @group integration
*/
public function testInvalidCredentials() {
$this->setExpectedException('PayPal\Exception\PPConnectionException');
$cred = new OAuthTokenCredential('dummy', 'secret');
$this->assertNull($cred->getAccessToken(PPConfigManager::getInstance()->getConfigHashmap()));
}
public function testInvalidCredentials()
{
$this->setExpectedException('PayPal\Exception\PPConnectionException');
$cred = new OAuthTokenCredential('dummy', 'secret');
$this->assertNull($cred->getAccessToken(PPConfigManager::getInstance()->getConfigHashmap()));
}
}

View File

@@ -1,29 +1,41 @@
<?php
namespace PayPal\Test\Common;
use PayPal\Common\PPModel;
class ArrayClass extends PPModel {
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
class ArrayClass extends PPModel
{
public function setDescription($desc) {
$this->desc = $desc;
}
public function getDescription() {
return $this->desc;
}
public function setTags($tags) {
if(!is_array($tags)) {
$tags = array($tags);
}
$this->tags = $tags;
}
public function getTags() {
return $this->tags;
}
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setDescription($description)
{
$this->description = $description;
}
public function getDescription()
{
return $this->description;
}
public function setTags($tags)
{
if (!is_array($tags)) {
$tags = array($tags);
}
$this->tags = $tags;
}
public function getTags()
{
return $this->tags;
}
}

View File

@@ -1,21 +1,24 @@
<?php
namespace PayPal\Test\Common;
use PayPal\Common\PPArrayUtil;
class ArrayUtilTest extends \PHPUnit_Framework_TestCase {
public function testIsAssocArray() {
$arr = array(1, 2, 3);
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
$arr = array(
'name' => 'John Doe',
'City' => 'San Jose'
);
$this->assertEquals(true, PPArrayUtil::isAssocArray($arr));
$arr[] = 'CA';
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
}
class ArrayUtilTest extends \PHPUnit_Framework_TestCase
{
public function testIsAssocArray()
{
$arr = array(1, 2, 3);
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
$arr = array(
'name' => 'John Doe',
'City' => 'San Jose'
);
$this->assertEquals(true, PPArrayUtil::isAssocArray($arr));
$arr[] = 'CA';
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
}
}

View File

@@ -1,6 +1,9 @@
<?php
namespace PayPal\Test\Common;
use PayPal\Common\PPModel;
class ChildClass extends SimpleClass {
class ChildClass extends SimpleClass
{
}

View File

@@ -1,66 +1,167 @@
<?php
<?php
namespace PayPal\Test\Common;
use PayPal\Common\PPModel;
use PayPal\Test\Common\ArrayClass;
use PayPal\Test\Common\SimpleClass;
use PayPal\Test\Common\NestedClass;
class ModelTest extends \PHPUnit_Framework_TestCase {
public function testSimpleClassConversion() {
$o = new SimpleClass();
$o->setName("test");
$o->setDescription("description");
$this->assertEquals("test", $o->getName());
$this->assertEquals("description", $o->getDescription());
$json = $o->toJSON();
$this->assertEquals('{"name":"test","desc":"description"}', $json);
$newO = new SimpleClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
public function testArrayClassConversion() {
$o = new ArrayClass();
$o->setName("test");
$o->setDescription("description");
$o->setTags(array('payment', 'info', 'test'));
$this->assertEquals("test", $o->getName());
$this->assertEquals("description", $o->getDescription());
$this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
$json = $o->toJSON();
$this->assertEquals('{"name":"test","desc":"description","tags":["payment","info","test"]}', $json);
$newO = new ArrayClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
public function testNestedClassConversion() {
$n = new ArrayClass();
$n->setName("test");
$n->setDescription("description");
// $n->setTags(array('payment', 'info', 'test'));
$o = new NestedClass();
$o->setId('123');
$o->setInfo($n);
$this->assertEquals("123", $o->getId());
$this->assertEquals("test", $o->getInfo()->getName());
// $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags());
$json = $o->toJSON();
// $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json);
$this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json);
$newO = new NestedClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
use PayPal\Core\PPConfigManager;
class ModelTest extends \PHPUnit_Framework_TestCase
{
public function testSimpleClassConversion()
{
$o = new SimpleClass();
$o->setName("test");
$o->setDescription("description");
$this->assertEquals("test", $o->getName());
$this->assertEquals("description", $o->getDescription());
$json = $o->toJSON();
$this->assertEquals('{"name":"test","description":"description"}', $json);
$newO = new SimpleClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
public function testConstructorJSON()
{
$obj = new SimpleClass('{"name":"test","description":"description"}');
$this->assertEquals($obj->getName(), "test");
$this->assertEquals($obj->getDescription(), "description");
}
public function testConstructorArray()
{
$arr = array('name' => 'test', 'description' => 'description');
$obj = new SimpleClass($arr);
$this->assertEquals($obj->getName(), "test");
$this->assertEquals($obj->getDescription(), "description");
}
public function testConstructorNull()
{
$obj = new SimpleClass(null);
$this->assertNotEquals($obj->getName(), "test");
$this->assertNotEquals($obj->getDescription(), "description");
$this->assertNull($obj->getName());
$this->assertNull($obj->getDescription());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage data should be either json or array representation of object
*/
public function testConstructorInvalidInput()
{
new SimpleClass("Something that is not even correct");
}
public function testSimpleClassObjectConversion()
{
$json = '{"name":"test","description":"description"}';
$obj = new SimpleClass();
$obj->fromJson($json);
$this->assertEquals("test", $obj->getName());
$this->assertEquals("description", $obj->getDescription());
}
public function testSimpleClassObjectInvalidConversion()
{
try {
$json = '{"name":"test","description":"description","invalid":"value"}';
$obj = new SimpleClass();
$obj->fromJson($json);
$this->assertEquals("test", $obj->getName());
$this->assertEquals("description", $obj->getDescription());
} catch (\PHPUnit_Framework_Error_Notice $ex) {
echo $ex->getMessage();
}
}
/**
* @outputBuffering enabled
*/
public function testInvalidMagicMethod()
{
$obj = new SimpleClass();
try {
$obj->invalid = "value2";
$this->assertEquals($obj->invalid, "value2");
if (PPConfigManager::getInstance()->get('validation.level') == 'strict') {
$this->fail("It should have thrown a Notice Error");
}
} catch (\PHPUnit_Framework_Error_Notice $ex) {
}
}
/**
* @outputBuffering enabled
*/
public function testInvalidMagicMethodWithDisabledValidation()
{
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'disabled'));
$obj = new SimpleClass();
try {
$obj->invalid = "value2";
$this->assertEquals($obj->invalid, "value2");
} catch (\PHPUnit_Framework_Error_Notice $ex) {
$this->fail("It should not have thrown a Notice Error as it is disabled.");
}
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict'));
}
public function testInvalidMagicMethodWithValidationLevel()
{
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'log'));
$obj = new SimpleClass();
$obj->invalid2 = "value2";
$this->assertEquals($obj->invalid2, "value2");
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict'));
}
public function testArrayClassConversion()
{
$o = new ArrayClass();
$o->setName("test");
$o->setDescription("description");
$o->setTags(array('payment', 'info', 'test'));
$this->assertEquals("test", $o->getName());
$this->assertEquals("description", $o->getDescription());
$this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
$json = $o->toJSON();
$this->assertEquals('{"name":"test","description":"description","tags":["payment","info","test"]}', $json);
$newO = new ArrayClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
public function testNestedClassConversion()
{
$n = new ArrayClass();
$n->setName("test");
$n->setDescription("description");
$o = new NestedClass();
$o->setId('123');
$o->setInfo($n);
$this->assertEquals("123", $o->getId());
$this->assertEquals("test", $o->getInfo()->getName());
$json = $o->toJSON();
$this->assertEquals('{"id":"123","info":{"name":"test","description":"description"}}', $json);
$newO = new NestedClass();
$newO->fromJson($json);
$this->assertEquals($o, $newO);
}
}

View File

@@ -1,27 +1,36 @@
<?php
namespace PayPal\Test\Common;
use PayPal\Common\PPModel;
class NestedClass extends PPModel {
public function setId($id) {
$this->id = $id;
}
public function getId() {
return $this->id;
}
/**
*
* @param PayPal\Test\Common\ArrayClass $info
*/
public function setInfo($info) {
$this->info = $info;
}
/**
*
* @return PayPal\Test\Common\ArrayClass
*/
public function getInfo() {
return $this->info;
}
class NestedClass extends PPModel
{
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
/**
*
* @param PayPal\Test\Common\ArrayClass $info
*/
public function setInfo($info)
{
$this->info = $info;
}
/**
*
* @return PayPal\Test\Common\ArrayClass
*/
public function getInfo()
{
return $this->info;
}
}

View File

@@ -2,130 +2,144 @@
use PayPal\Common\PPModel;
class SimpleModelTestClass extends PPModel {
/**
*
* @access public
* @param string $field1
*/
public function setField1($field1) {
$this->field1 = $field1;
return $this;
}
/**
*
* @access public
* @return string
*/
public function getField1() {
return $this->field1;
}
/**
*
* @access public
* @param string $field2
*/
public function setField2($field2) {
$this->field2 = $field2;
return $this;
}
/**
*
* @access public
* @return string
*/
public function getField2() {
return $this->field2;
}
class SimpleModelTestClass extends PPModel
{
/**
*
* @access public
* @param string $field1
*/
public function setField1($field1)
{
$this->field1 = $field1;
return $this;
}
/**
*
* @access public
* @return string
*/
public function getField1()
{
return $this->field1;
}
/**
*
* @access public
* @param string $field2
*/
public function setField2($field2)
{
$this->field2 = $field2;
return $this;
}
/**
*
* @access public
* @return string
*/
public function getField2()
{
return $this->field2;
}
}
class ContainerModelTestClass extends PPModel
{
class ContainerModelTestClass extends PPModel {
/**
*
* @access public
* @param string $field1
*/
public function setField1($field1)
{
$this->field1 = $field1;
return $this;
}
/**
*
* @access public
* @param string $field1
*/
public function setField1($field1) {
$this->field1 = $field1;
return $this;
}
/**
*
* @access public
* @return string
*/
public function getField1()
{
return $this->field1;
}
/**
*
* @access public
* @return string
*/
public function getField1() {
return $this->field1;
}
/**
*
* @access public
* @param SimpleModelTestClass $field1
*/
public function setNested1($nested1)
{
$this->nested1 = $nested1;
return $this;
}
/**
*
* @access public
* @param SimpleModelTestClass $field1
*/
public function setNested1($nested1) {
$this->nested1 = $nested1;
return $this;
}
/**
*
* @access public
* @return SimpleModelTestClass
*/
public function getNested1() {
return $this->nested1;
}
/**
*
* @access public
* @return SimpleModelTestClass
*/
public function getNested1()
{
return $this->nested1;
}
}
class ListModelTestClass extends PPModel {
class ListModelTestClass extends PPModel
{
/**
*
* @access public
* @param string $list1
*/
public function setList1($list1) {
$this->list1 = $list1;
}
/**
*
* @access public
* @param string $list1
*/
public function setList1($list1)
{
$this->list1 = $list1;
}
/**
*
* @access public
* @return string
*/
public function getList1() {
return $this->list1;
}
/**
*
* @access public
* @return string
*/
public function getList1()
{
return $this->list1;
}
/**
*
* @access public
* @param SimpleModelTestClass $list2 array of SimpleModelTestClass
*/
public function setList2($list2) {
$this->list2 = $list2;
return $this;
}
/**
*
* @access public
* @param SimpleModelTestClass $list2 array of SimpleModelTestClass
*/
public function setList2($list2)
{
$this->list2 = $list2;
return $this;
}
/**
*
* @access public
* @return SimpleModelTestClass array of SimpleModelTestClass
*/
public function getList2() {
return $this->list2;
}
/**
*
* @access public
* @return SimpleModelTestClass array of SimpleModelTestClass
*/
public function getList2()
{
return $this->list2;
}
}
@@ -136,93 +150,99 @@ class ListModelTestClass extends PPModel {
*/
class PPModelTest extends PHPUnit_Framework_TestCase
{
/**
* 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 testSimpleConversion() {
$o = new SimpleModelTestClass();
$o->setField1('value 1');
$o->setField2("value 2");
$this->assertEquals('{"field1":"value 1","field2":"value 2"}', $o->toJSON());
$oCopy = new SimpleModelTestClass();
$oCopy->fromJson($o->toJSON());
$this->assertEquals($o, $oCopy);
}
/**
* @test
*/
public function testSpecialChars() {
$o = new SimpleModelTestClass();
$o->setField1('value "1');
$o->setField2("value 2");
$this->assertEquals('{"field1":"value \"1","field2":"value 2"}', $o->toJSON());
$oCopy = new SimpleModelTestClass();
$oCopy->fromJson($o->toJSON());
$this->assertEquals($o, $oCopy);
}
/**
* @test
*/
public function testNestedConversion() {
$child = new SimpleModelTestClass();
$child->setField1('value 1');
$child->setField2("value 2");
$parent = new ContainerModelTestClass();
$parent->setField1("parent");
$parent->setNested1($child);
$this->assertEquals('{"field1":"parent","nested1":{"field1":"value 1","field2":"value 2"}}',
$parent->toJSON());
$parentCopy = new ContainerModelTestClass();
$parentCopy->fromJson($parent->toJSON());
$this->assertEquals($parent, $parentCopy);
}
/**
* @test
*/
public function testListConversion() {
$c1 = new SimpleModelTestClass();
$c1->setField1("a")->setField2('value');
$c2 = new SimpleModelTestClass();
$c1->setField1("another")->setField2('object');
$parent = new ListModelTestClass();
$parent->setList1(array('simple', 'list', 'with', 'integer', 'keys'));
$parent->setList2(array($c1, $c2));
$parentCopy = new ListModelTestClass();
$parentCopy->fromJson($parent->toJSON());
$this->assertEquals($parent, $parentCopy);
}
/**
* 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 testSimpleConversion()
{
$o = new SimpleModelTestClass();
$o->setField1('value 1');
$o->setField2("value 2");
$this->assertEquals('{"field1":"value 1","field2":"value 2"}', $o->toJSON());
$oCopy = new SimpleModelTestClass();
$oCopy->fromJson($o->toJSON());
$this->assertEquals($o, $oCopy);
}
/**
* @test
*/
public function testSpecialChars()
{
$o = new SimpleModelTestClass();
$o->setField1('value "1');
$o->setField2("value 2");
$this->assertEquals('{"field1":"value \"1","field2":"value 2"}', $o->toJSON());
$oCopy = new SimpleModelTestClass();
$oCopy->fromJson($o->toJSON());
$this->assertEquals($o, $oCopy);
}
/**
* @test
*/
public function testNestedConversion()
{
$child = new SimpleModelTestClass();
$child->setField1('value 1');
$child->setField2("value 2");
$parent = new ContainerModelTestClass();
$parent->setField1("parent");
$parent->setNested1($child);
$this->assertEquals('{"field1":"parent","nested1":{"field1":"value 1","field2":"value 2"}}',
$parent->toJSON());
$parentCopy = new ContainerModelTestClass();
$parentCopy->fromJson($parent->toJSON());
$this->assertEquals($parent, $parentCopy);
}
/**
* @test
*/
public function testListConversion()
{
$c1 = new SimpleModelTestClass();
$c1->setField1("a")->setField2('value');
$c2 = new SimpleModelTestClass();
$c1->setField1("another")->setField2('object');
$parent = new ListModelTestClass();
$parent->setList1(array('simple', 'list', 'with', 'integer', 'keys'));
$parent->setList2(array($c1, $c2));
$parentCopy = new ListModelTestClass();
$parentCopy->fromJson($parent->toJSON());
$this->assertEquals($parent, $parentCopy);
}
}

View File

@@ -1,19 +1,28 @@
<?php
namespace PayPal\Test\Common;
use PayPal\Common\PPModel;
class SimpleClass extends PPModel {
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function setDescription($desc) {
$this->desc = $desc;
}
public function getDescription() {
return $this->desc;
}
use PayPal\Common\PPModel;
class SimpleClass extends PPModel
{
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setDescription($description)
{
$this->description = $description;
}
public function getDescription()
{
return $this->description;
}
}

View File

@@ -2,25 +2,27 @@
use PayPal\Common\PPUserAgent;
class UserAgentTest extends PHPUnit_Framework_TestCase {
public function testGetValue() {
$ua = PPUserAgent::getValue("name", "version");
list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
// Check that we pass the useragent in the expected format
$this->assertNotNull($id);
$this->assertNotNull($version);
$this->assertNotNull($features);
$this->assertEquals("name", $id);
$this->assertEquals("version", $version);
// Check that we pass in these mininal features
$this->assertThat($features, $this->stringContains("OS="));
$this->assertThat($features, $this->stringContains("Bit="));
$this->assertThat($features, $this->stringContains("Lang="));
$this->assertThat($features, $this->stringContains("V="));
$this->assertGreaterThan(5, count(explode(';', $features)));
}
class UserAgentTest extends PHPUnit_Framework_TestCase
{
public function testGetValue()
{
$ua = PPUserAgent::getValue("name", "version");
list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
// Check that we pass the useragent in the expected format
$this->assertNotNull($id);
$this->assertNotNull($version);
$this->assertNotNull($features);
$this->assertEquals("name", $id);
$this->assertEquals("version", $version);
// Check that we pass in these mininal features
$this->assertThat($features, $this->stringContains("OS="));
$this->assertThat($features, $this->stringContains("Bit="));
$this->assertThat($features, $this->stringContains("Lang="));
$this->assertThat($features, $this->stringContains("V="));
$this->assertGreaterThan(5, count(explode(';', $features)));
}
}

View File

@@ -1,7 +1,8 @@
<?php
namespace PayPal\Test;
class Constants {
const CLIENT_ID = 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM';
const CLIENT_SECRET = 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM';
class Constants
{
const CLIENT_ID = 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM';
const CLIENT_SECRET = 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM';
}

View File

@@ -1,5 +1,6 @@
<?php
use PayPal\Core\PPCredentialManager;
/**
* Test class for PPCredentialManager.
*
@@ -7,68 +8,70 @@ use PayPal\Core\PPCredentialManager;
*/
class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PPCredentialManager
*/
protected $object;
/**
* @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);
}
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',
);
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* 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);
}
/**
* @test
*/
public function testGetInstance()
{
$instance = $this->object->getInstance($this->config);
$this->assertTrue($instance instanceof PPCredentialManager);
}
/**
* 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 testGetSpecificCredentialObject()
{
$cred = $this->object->getCredentialObject('acct1');
$this->assertNotNull($cred);
/**
* @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() {
public function testSetCredentialObject()
{
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
->disableOriginalConstructor()
->getMock();
@@ -83,7 +86,8 @@ class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
*
* @throws \PayPal\Exception\PPInvalidCredentialException
*/
public function testSetCredentialObjectWithUserId() {
public function testSetCredentialObjectWithUserId()
{
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
->disableOriginalConstructor()
->getMock();
@@ -97,7 +101,8 @@ class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
*
* @throws \PayPal\Exception\PPInvalidCredentialException
*/
public function testSetCredentialObjectWithoutDefault() {
public function testSetCredentialObjectWithoutDefault()
{
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
->disableOriginalConstructor()
->getMock();
@@ -107,39 +112,39 @@ class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
}
/**
* @test
*/
public function testGetInvalidCredentialObject()
{
$this->setExpectedException('PayPal\Exception\PPInvalidCredentialException');
$cred = $this->object->getCredentialObject('invalid_biz_api1.gmail.com');
}
/**
* @test
*/
public function testGetInvalidCredentialObject()
{
$this->setExpectedException('PayPal\Exception\PPInvalidCredentialException');
$cred = $this->object->getCredentialObject('invalid_biz_api1.gmail.com');
}
/**
*
*/
public function testGetDefaultCredentialObject()
{
*/
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);
/**
* @test
*/
public function testGetRestCredentialObject()
{
$cred = $this->object->getCredentialObject('acct1');
$this->assertAttributeEquals($this->config['acct1.ClientId'], 'clientId', $cred);
$this->assertNotNull($cred);
$this->assertAttributeEquals($this->config['acct1.ClientId'], 'clientId', $cred);
$this->assertAttributeEquals($this->config['acct1.ClientSecret'], 'clientSecret', $cred);
}
}
}
?>

View File

@@ -1,17 +1,18 @@
<?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' ,
'http.ConnectionTimeOut' => '30',
'http.Retry' => '5',
);
/**
@@ -20,7 +21,7 @@ class PPHttpConfigTest extends PHPUnit_Framework_TestCase
*/
protected function setUp()
{
}
/**
@@ -35,87 +36,88 @@ class PPHttpConfigTest extends PHPUnit_Framework_TestCase
* @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'));
{
$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']);
$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]);
$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]);
$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');
$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

@@ -1,5 +1,6 @@
<?php
use PayPal\Core\PPLoggingManager;
/**
* Test class for PPLoggingManager.
*
@@ -17,7 +18,7 @@ class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
$this->object = new PPLoggingManager('InvoiceTest');
$this->object = PPLoggingManager::getInstance('InvoiceTest');
}
/**
@@ -33,7 +34,7 @@ class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
*/
public function testError()
{
$this->object->error('Test Error Message');
$this->object->error('Test Error Message');
}
@@ -42,7 +43,7 @@ class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
*/
public function testWarning()
{
$this->object->warning('Test Warning Message');
$this->object->warning('Test Warning Message');
}
/**
@@ -58,7 +59,8 @@ class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
*/
public function testFine()
{
$this->object->fine('Test fine Message');
$this->object->fine('Test fine Message');
}
}
?>

View File

@@ -1,5 +1,6 @@
<?php
use PayPal\Exception\PPConfigurationException;
/**
* Test class for PPConfigurationException.
*
@@ -27,9 +28,11 @@ class PPConfigurationExceptionTest extends \PHPUnit_Framework_TestCase
protected function tearDown()
{
}
public function testPPConfigurationException()
{
$this->assertEquals('Test PPConfigurationException', $this->object->getMessage());
$this->assertEquals('Test PPConfigurationException', $this->object->getMessage());
}
}
?>

View File

@@ -1,5 +1,6 @@
<?php
use PayPal\Exception\PPConnectionException;
/**
* Test class for PPConnectionException.
*
@@ -34,15 +35,16 @@ class PPConnectionExceptionTest extends \PHPUnit_Framework_TestCase
*/
public function testGetUrl()
{
$this->assertEquals('http://testURL', $this->object->getUrl());
$this->assertEquals('http://testURL', $this->object->getUrl());
}
/**
* @test
*/
public function testGetData()
public function testGetData()
{
$this->assertEquals('response payload for connection', $this->object->getData());
$this->assertEquals('response payload for connection', $this->object->getData());
}
}
?>

View File

@@ -1,5 +1,6 @@
<?php
use PayPal\Exception\PPInvalidCredentialException;
/**
* Test class for PPInvalidCredentialException.
*
@@ -33,8 +34,9 @@ class PPInvalidCredentialExceptionTest extends \PHPUnit_Framework_TestCase
*/
public function testErrorMessage()
{
$msg = $this->object->errorMessage();
$this->assertContains('Error on line', $msg);
$msg = $this->object->errorMessage();
$this->assertContains('Error on line', $msg);
}
}
?>

View File

@@ -34,8 +34,9 @@ class PPMissingCredentialExceptionTest extends \PHPUnit_Framework_TestCase
*/
public function testErrorMessage()
{
$msg = $this->object->errorMessage();
$this->assertContains('Error on line', $msg);
$msg = $this->object->errorMessage();
$this->assertContains('Error on line', $msg);
}
}
?>

View File

@@ -7,35 +7,39 @@ use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\Call;
use PayPal\Test\Constants;
class CallTest {
class CallTest
{
public function testExecuteWithExplicitCredentials() {
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
$data = '"request":"test message"';
public function testExecuteWithExplicitCredentials()
{
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
$data = '"request":"test message"';
$call = new Call();
$ret = $call->execute('/v1/payments/echo', "POST", $data, $cred);
$this->assertEquals($data, $ret);
}
$call = new Call();
$ret = $call->execute('/v1/payments/echo', "POST", $data, $cred);
$this->assertEquals($data, $ret);
}
public function testExecuteWithInvalidCredentials() {
public function testExecuteWithInvalidCredentials()
{
$cred = new OAuthTokenCredential('test', 'dummy');
$data = '"request":"test message"';
$cred = new OAuthTokenCredential('test', 'dummy');
$data = '"request":"test message"';
$call = new Call();
$this->setExpectedException('\PPConnectionException');
$ret = $call->execute('/v1/payments/echo', "POST", $data, $cred);
$call = new Call();
$this->setExpectedException('\PPConnectionException');
$ret = $call->execute('/v1/payments/echo', "POST", $data, $cred);
}
}
public function testExecuteWithDefaultCredentials() {
public function testExecuteWithDefaultCredentials()
{
$data = '"request":"test message"';
$data = '"request":"test message"';
$call = new Call();
$ret = $call->execute('/v1/payments/echo', "POST", $data);
$this->assertEquals($data, $ret);
}
$call = new Call();
$ret = $call->execute('/v1/payments/echo', "POST", $data);
$this->assertEquals($data, $ret);
}
}

View File

@@ -23,7 +23,6 @@ service.EndPoint="https://api.sandbox.paypal.com"
;Logging Information
[Log]
log.LogEnabled=true
; When using a relative path, the log file is created
@@ -36,3 +35,13 @@ log.FileName=PayPal.log
; Logging is most verbose in the 'FINE' level and
; decreases as you proceed towards ERROR
log.LogLevel=FINE
;Validation Configuration
[validation]
; If validation is set to strict, the PPModel would make sure that
; there are proper accessors (Getters and Setters) for each model
; objects. Accepted value is
; 'log' : logs the error message to logger only (default)
; 'strict' : throws a php notice message
; 'disable' : disable the validation
validation.level=strict