mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
add tests for order entity
This commit is contained in:
parent
b06716bb14
commit
6a6e088846
2 changed files with 87 additions and 2 deletions
|
@ -90,8 +90,7 @@ class Order
|
|||
'id' => $this->id(),
|
||||
'intent' => $this->intent(),
|
||||
'status' => $this->status()->name(),
|
||||
'purchase_units' => array_map(
|
||||
function (PurchaseUnit $unit) : array {
|
||||
'purchase_units' => array_map(function (PurchaseUnit $unit) : array {
|
||||
return $unit->toArray();
|
||||
},
|
||||
$this->purchaseUnits()
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\ApiClient\Endpoint;
|
||||
|
||||
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\Order;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\Payer;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||
use Inpsyde\PayPalCommerce\ApiClient\TestCase;
|
||||
use Mockery;
|
||||
class OrderTest extends TestCase
|
||||
{
|
||||
|
||||
public function testOrder() {
|
||||
|
||||
$id = 'id';
|
||||
$createTime = new \DateTime();
|
||||
$updateTime = new \DateTime();
|
||||
$unit = Mockery::mock(PurchaseUnit::class);
|
||||
$unit->expects('toArray')->andReturn([1]);
|
||||
$status = Mockery::mock(OrderStatus::class);
|
||||
$status->expects('name')->andReturn('CREATED');
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$payer
|
||||
->expects('toArray')->andReturn(['payer']);
|
||||
$intent = 'AUTHORIZE';
|
||||
|
||||
$testee = new Order(
|
||||
$id,
|
||||
[$unit],
|
||||
$status,
|
||||
$payer,
|
||||
$intent,
|
||||
$createTime,
|
||||
$updateTime
|
||||
);
|
||||
|
||||
$this->assertEquals($id, $testee->id());
|
||||
$this->assertEquals($createTime, $testee->createTime());
|
||||
$this->assertEquals($updateTime, $testee->updateTime());
|
||||
$this->assertEquals([$unit], $testee->purchaseUnits());
|
||||
$this->assertEquals($payer, $testee->payer());
|
||||
$this->assertEquals($intent, $testee->intent());
|
||||
$this->assertEquals($status, $testee->status());
|
||||
|
||||
$expected = [
|
||||
'id' => $id,
|
||||
'intent' => $intent,
|
||||
'status' => 'CREATED',
|
||||
'purchase_units' => [
|
||||
[1],
|
||||
],
|
||||
'create_time' => $createTime->format(\DateTimeInterface::ISO8601),
|
||||
'update_time' => $updateTime->format(\DateTimeInterface::ISO8601),
|
||||
'payer' => ['payer'],
|
||||
];
|
||||
$this->assertEquals($expected, $testee->toArray());
|
||||
}
|
||||
|
||||
public function testOrderNoDatesOrPayer() {
|
||||
|
||||
$id = 'id';
|
||||
$unit = Mockery::mock(PurchaseUnit::class);
|
||||
$unit->expects('toArray')->andReturn([1]);
|
||||
$status = Mockery::mock(OrderStatus::class);
|
||||
$status->expects('name')->andReturn('CREATED');
|
||||
|
||||
$testee = new Order(
|
||||
$id,
|
||||
[$unit],
|
||||
$status
|
||||
);
|
||||
|
||||
$this->assertEquals(null, $testee->createTime());
|
||||
$this->assertEquals(null, $testee->updateTime());
|
||||
$this->assertEquals(null, $testee->payer());
|
||||
$this->assertEquals('CAPTURE', $testee->intent());
|
||||
|
||||
$array = $testee->toArray();
|
||||
$this->assertFalse(array_key_exists('payer', $array));
|
||||
$this->assertFalse(array_key_exists('create_time', $array));
|
||||
$this->assertFalse(array_key_exists('update_time', $array));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue