Skip to content

Commit

Permalink
Unit tests for APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ebcayabyab committed Jul 12, 2016
1 parent e909093 commit fd85b53
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 10 deletions.
61 changes: 59 additions & 2 deletions tests/PayMaya/Test/API/CheckoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,65 @@
namespace PayMaya\Test\API;

use PayMaya\API\Checkout;
use PayMaya\Test\Model\Checkout\BuyerTest;
use PayMaya\Test\Model\Checkout\ItemTest;
use PayMaya\Test\Model\Checkout\ItemAmountTest;

class CheckoutTest extends \PHPUnit_Framework_TestCase
{

}
public static function getObject()
{
$checkout = new Checkout();
$checkout->buyer = BuyerTest::getObject();
$checkout->items = array(ItemTest::getObject());
$checkout->totalAmount = ItemAmountTest::getObject();
$checkout->requestReferenceNumber = "123456789";
$checkout->redirectUrl = array(
"success" => "https://shop.com/success",
"failure" => "https://shop.com/failure",
"cancel" => "https://shop.com/cancel"
);
return $checkout;
}

public function testInitialization()
{
$obj = self::getObject();
$this->assertEquals($obj->buyer, BuyerTest::getObject());
$this->assertEquals($obj->items, array(ItemTest::getObject()));
$this->assertEquals($obj->totalAmount, ItemAmountTest::getObject());
$this->assertEquals($obj->requestReferenceNumber, "123456789");
$this->assertEquals($obj->redirectUrl, array(
"success" => "https://shop.com/success",
"failure" => "https://shop.com/failure",
"cancel" => "https://shop.com/cancel"
));
return $obj;
}

/**
* @depends testInitialization
*/
public function testExecute($obj)
{
$obj->execute();
$this->assertNotNull($obj->id);
$this->assertNotNull($obj->url);
return $obj;
}

/**
* @depends testExecute
*/
public function testRetrieve($obj)
{
$obj->retrieve();
$this->assertNotNull($obj->status);
$this->assertNotNull($obj->paymentType);
$this->assertNotNull($obj->transactionReferenceNumber);
$this->assertNotNull($obj->receiptNumber);
$this->assertNotNull($obj->paymentStatus);
$this->assertNotNull($obj->voidStatus);
$this->assertNotNull($obj->metadata);
}
}
66 changes: 62 additions & 4 deletions tests/PayMaya/Test/API/CustomizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,68 @@

namespace PayMaya\Test\API;

use PHPUnit\Framework\TestCase;
use PayMaya\API\Customization;

class CustomizationTest extends TestCase
class CustomizationTest extends \PHPUnit_Framework_TestCase
{

}
public static function getObject()
{
$customization = new Customization();
$customization->logoUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg";
$customization->iconUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico";
$customization->appleTouchIconUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico";
$customization->customTitle = "Checkout Page Title";
$customization->colorScheme = "#368d5c";
return $customization;
}

public function testRemove()
{
$obj = self::getObject();
$obj->remove();
$this->assertNull($obj->logoUrl);
$this->assertNull($obj->iconUrl);
$this->assertNull($obj->appleTouchIconUrl);
$this->assertNull($obj->customTitle);
$this->assertNull($obj->colorScheme);
}

public function testInitialization()
{
$obj = self::getObject();
$this->assertEquals($obj->logoUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg");
$this->assertEquals($obj->iconUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico");
$this->assertEquals($obj->appleTouchIconUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico");
$this->assertEquals($obj->customTitle, "Checkout Page Title");
$this->assertEquals($obj->colorScheme, "#368d5c");
return $obj;
}

/**
* @depends testInitialization
*/
public function testSet($obj)
{
$obj->set();
$this->assertEquals($obj->logoUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg");
$this->assertEquals($obj->iconUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico");
$this->assertEquals($obj->appleTouchIconUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico");
$this->assertEquals($obj->customTitle, "Checkout Page Title");
$this->assertEquals($obj->colorScheme, "#368d5c");
return $obj;
}

/**
* @depends testSet
*/
public function testGet($obj)
{
$obj->get();
$this->assertEquals($obj->logoUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg");
$this->assertEquals($obj->iconUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico");
$this->assertEquals($obj->appleTouchIconUrl, "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico");
$this->assertEquals($obj->customTitle, "Checkout Page Title");
$this->assertEquals($obj->colorScheme, "#368d5c");
return $obj;
}
}
62 changes: 58 additions & 4 deletions tests/PayMaya/Test/API/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,64 @@

namespace PayMaya\Test\API;

use PHPUnit\Framework\TestCase;
use PayMaya\API\Webhook;

class WebhookTest extends TestCase
class WebhookTest extends \PHPUnit_Framework_TestCase
{

}
public static function getObject()
{
$webhook = new Webhook();
$webhook->name = Webhook::CHECKOUT_SUCCESS;
$webhook->callbackUrl = "http://shop.someserver.com/success";
return $webhook;
}

public function testInitialization()
{
$obj = self::getObject();
$this->assertEquals($obj->name, Webhook::CHECKOUT_SUCCESS);
$this->assertEquals($obj->callbackUrl, "http://shop.someserver.com/success");
return $obj;
}

/**
* @depends testInitialization
*/
public function testRegister($obj)
{
$obj->register();
$this->assertNotNull($obj->id);
return $obj;
}

/**
* @depends testRegister
*/
public function testRetrieve($obj)
{
$webhooks = Webhook::retrieve();
$this->assertNotEmpty($webhooks);
}

/**
* @depends testRegister
*/
public function testUpdate($obj)
{
$obj->callbackUrl = "http://shop.someserver.com/successUpdated";
$obj->update();
$this->assertEquals($obj->callbackUrl, "http://shop.someserver.com/successUpdated");
return $obj;
}

/**
* @depends testUpdate
*/
public function testDelete($obj)
{
$obj->delete();
$this->assertNull($obj->id);
$this->assertNull($obj->name);
$this->assertNull($obj->callbackUrl);
}
}

0 comments on commit fd85b53

Please sign in to comment.