Fixed testcases

This commit is contained in:
siddick
2014-03-28 22:41:48 +05:30
parent 699d6b86f1
commit 5963119d99
3 changed files with 49 additions and 50 deletions

View File

@@ -5,9 +5,9 @@ use PayPal\Api\Address;
use PayPal\Api\CreditCard;
use PayPal\Test\Constants;
class CreditCardTest extends \PHPUnit_Framework_TestCase {
private $cards;
public static $id = "id";
public static $validUntil = "2013-02-28T00:00:00Z";
public static $state = "created";
@@ -19,7 +19,7 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase {
public static $cvv = "012";
public static $firstName = "V";
public static $lastName = "C";
public static function createCreditCard() {
$card = new CreditCard();
$card->setType(self::$cardType);
@@ -29,24 +29,21 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase {
$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->setBillingAddress(AddressTest::createAddress());
$card->setLinks(array(LinksTest::createLinks()));
$this->cards['full'] = $card;
$card = self::createCreditCard();
$card = self::createCreditCard();
$this->cards['partial'] = $card;
}
public function testGetterSetters() {
$c = $this->cards['partial'];
$this->assertEquals(self::$cardType, $c->getType());
@@ -56,34 +53,32 @@ class CreditCardTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(self::$cvv, $c->getCvv2());
$this->assertEquals(self::$firstName, $c->getFirstName());
$this->assertEquals(self::$lastName, $c->getLastName());
$this->assertEquals(self::$id, $c->getId());
$this->assertEquals(self::$validUntil, $c->getValidUntil());
$this->assertEquals(self::$state, $c->getState());
$this->assertEquals(self::$payerId, $c->getPayerId());
$c = $this->cards['full'];
$this->assertEquals(AddressTest::$line1, $c->getBillingAddress()->getLine1());
$link = $c->getLinks();
$this->assertEquals(LinksTest::$href, $link[0]->getHref());
}
public function testSerializeDeserialize() {
$c1 = $this->cards['full'];
$json = $c1->toJson();
$c2 = new CreditCard();
$c2->fromJson($json);
$c2->fromJson($json);
$this->assertEquals($c1, $c2);
}
public function testOperations() {
$c1 = $this->cards['full'];
// $this->assertNull($c1->getId());
$c1->create();
$c1->create();
$this->assertNotNull($c1->getId());
$c2 = CreditCard::get($c1->getId());
$this->assertEquals($c1->getBillingAddress(), $c2->getBillingAddress());
$this->assertGreaterThan(0, count($c2->getLinks()));

View File

@@ -15,22 +15,22 @@ class FundingInstrumentTest extends \PHPUnit_Framework_TestCase {
$fi->setCreditCardToken(CreditCardTokenTest::createCreditCardToken());
return $fi;
}
public function setup() {
$this->fi = self::createFundingInstrument();
}
public function testGetterSetter() {
$this->assertEquals(CreditCardTest::$cardNumber, $this->fi->getCreditCard()->getNumber());
$this->assertEquals(CreditCardTokenTest::$creditCardId,
$this->assertEquals(CreditCardTokenTest::$creditCardId,
$this->fi->getCreditCardToken()->getCreditCardId());
}
public function testSerializeDeserialize() {
$fi1 = $this->fi;
$fi2 = new FundingInstrument();
$fi2->fromJson($fi1->toJson());
$fi2->fromJson($fi1->toJson());
$this->assertEquals($fi1, $fi2);
}
}

View File

@@ -12,66 +12,70 @@ use PayPal\Test\Constants;
class PaymentTest extends \PHPUnit_Framework_TestCase {
private $payments;
private $payments;
public static function createPayment() {
$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()));
return $payment;
return $payment;
}
public static function createNewPayment() {
$funding = FundingInstrumentTest::createFundingInstrument();
$funding->credit_card_token = null;
$payer = new Payer();
$payer->setPaymentMethod("credit_card");
$payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument()));
$payer->setFundingInstruments(array($funding));
$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");
$payment = new Payment();
$payment->setIntent("sale");
$payment->setRedirectUrls($redirectUrls);
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
return $payment;
return $payment;
}
public function setup() {
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());
$p2->fromJson($this->payments['full']->toJSON());
$this->assertEquals($p2, $this->payments['full']);
}
public function testOperations() {
$p1 = $this->payments['new'];
$p1->create();
$p1->create();
$this->assertNotNull($p1->getId());
$p2 = Payment::get($p1->getId());
$this->assertNotNull($p2);
$paymentHistory = Payment::all(array('count' => '10'));
$this->assertNotNull($paymentHistory);
}