forked from LiveCarta/PayPal-PHP-SDK
- Updated Unit Tests for PPModels used by Invoicing - Updated Functional Tests - Updated Samples for quick changes.
100 lines
2.9 KiB
PHP
100 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace PayPal\Test\Api;
|
|
|
|
use PayPal\Common\PPModel;
|
|
use PayPal\Api\InvoiceItem;
|
|
|
|
/**
|
|
* Class InvoiceItem
|
|
*
|
|
* @package PayPal\Test\Api
|
|
*/
|
|
class InvoiceItemTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* Gets Json String of Object InvoiceItem
|
|
* @return string
|
|
*/
|
|
public static function getJson()
|
|
{
|
|
return '{"name":"TestSample","description":"TestSample","quantity":"12.34","unit_price":' .CurrencyTest::getJson() . ',"tax":' .TaxTest::getJson() . ',"date":"TestSample","discount":' .CostTest::getJson() . '}';
|
|
}
|
|
|
|
/**
|
|
* Gets Object Instance with Json data filled in
|
|
* @return InvoiceItem
|
|
*/
|
|
public static function getObject()
|
|
{
|
|
return new InvoiceItem(self::getJson());
|
|
}
|
|
|
|
|
|
/**
|
|
* Tests for Serialization and Deserialization Issues
|
|
* @return InvoiceItem
|
|
*/
|
|
public function testSerializationDeserialization()
|
|
{
|
|
$obj = new InvoiceItem(self::getJson());
|
|
$this->assertNotNull($obj);
|
|
$this->assertNotNull($obj->getName());
|
|
$this->assertNotNull($obj->getDescription());
|
|
$this->assertNotNull($obj->getQuantity());
|
|
$this->assertNotNull($obj->getUnitPrice());
|
|
$this->assertNotNull($obj->getTax());
|
|
$this->assertNotNull($obj->getDate());
|
|
$this->assertNotNull($obj->getDiscount());
|
|
$this->assertEquals(self::getJson(), $obj->toJson());
|
|
return $obj;
|
|
}
|
|
|
|
/**
|
|
* @depends testSerializationDeserialization
|
|
* @param InvoiceItem $obj
|
|
*/
|
|
public function testGetters($obj)
|
|
{
|
|
$this->assertEquals($obj->getName(), "TestSample");
|
|
$this->assertEquals($obj->getDescription(), "TestSample");
|
|
$this->assertEquals($obj->getQuantity(), "12.34");
|
|
$this->assertEquals($obj->getUnitPrice(), CurrencyTest::getObject());
|
|
$this->assertEquals($obj->getTax(), TaxTest::getObject());
|
|
$this->assertEquals($obj->getDate(), "TestSample");
|
|
$this->assertEquals($obj->getDiscount(), CostTest::getObject());
|
|
}
|
|
|
|
/**
|
|
* @depends testSerializationDeserialization
|
|
* @param InvoiceItem $obj
|
|
*/
|
|
public function testDeprecatedGetters($obj)
|
|
{
|
|
$this->assertEquals($obj->getUnit_price(), CurrencyTest::getObject());
|
|
}
|
|
|
|
/**
|
|
* @depends testSerializationDeserialization
|
|
* @param InvoiceItem $obj
|
|
*/
|
|
public function testDeprecatedSetterNormalGetter($obj)
|
|
{
|
|
|
|
// Check for Unit_price
|
|
$obj->setUnitPrice(null);
|
|
$this->assertNull($obj->getUnit_price());
|
|
$this->assertNull($obj->getUnitPrice());
|
|
$this->assertSame($obj->getUnitPrice(), $obj->getUnit_price());
|
|
$obj->setUnit_price(CurrencyTest::getObject());
|
|
$this->assertEquals($obj->getUnit_price(), CurrencyTest::getObject());
|
|
|
|
//Test All Deprecated Getters and Normal Getters
|
|
$this->testDeprecatedGetters($obj);
|
|
$this->testGetters($obj);
|
|
}
|
|
|
|
|
|
|
|
}
|