Passed
Pull Request — master (#59)
by Raúl
04:00
created

OrderTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 52
c 1
b 0
f 0
dl 0
loc 128
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstantsNotChange() 0 9 1
A testImportEmptyDates() 0 15 3
A testConstructor() 0 27 1
A testImport() 0 15 3
1
<?php
2
3
namespace Test\Pagantis\OrdersApiClient\Model;
4
5
use Pagantis\OrdersApiClient\Model\Order;
6
use Test\Pagantis\OrdersApiClient\AbstractTest;
7
8
/**
9
 * Class OrderTest
10
 *
11
 * @package Test\Pagantis\OrdersApiClient\Model
12
 */
13
class OrderTest extends AbstractTest
14
{
15
    /**
16
     * Initial status of a order.
17
     */
18
    const STATUS_CREATED = 'CREATED';
19
20
    /**
21
     * Order has been authorized and initial payment has been approved. For finalizing the order
22
     * it's mandatory to confirm it.
23
     */
24
    const STATUS_AUTHORIZED = 'AUTHORIZED';
25
26
    /**
27
     * Order confirmed has been paid by customer and merchant has confirmed it. Payment is completed
28
     * and settlement will be created.
29
     */
30
    const STATUS_CONFIRMED = 'CONFIRMED';
31
32
    /**
33
     * Rejected by the risk engine, the transaction has been rejected and payment is no longer
34
     * expected nor possible.
35
     */
36
    const STATUS_REJECTED = 'REJECTED';
37
38
    /**
39
     * The order has been invalidated due to the expiration limit. If no action happens during the
40
     * defined time, the order could turn to invalidated.
41
     */
42
    const STATUS_INVALIDATED = 'INVALIDATED';
43
44
    /**
45
     * Undefined ERROR has occurred, please double check with the account manager or Pagantis support channels.
46
     */
47
    const STATUS_ERROR = 'ERROR';
48
49
    /**
50
     * If a order is not confirmed given the default confirmation time, defined previously, it will turn to
51
     * unconfirmed and this will refund any possible payment taken from the customer. The loan shall not be created.
52
     */
53
    const STATUS_UNCONFIRMED = 'UNCONFIRMED';
54
55
    /**
56
     * testConstructor
57
     */
58
    public function testConstructor()
59
    {
60
        $order = new Order();
61
        $this->assertInstanceOf(
62
            'Pagantis\OrdersApiClient\Model\Order\User',
63
            $order->getUser()
64
        );
65
        $this->assertNull(
66
            $order->getActionUrls()
67
        );
68
        $this->assertInstanceOf(
69
            'Pagantis\OrdersApiClient\Model\Order\Configuration',
70
            $order->getConfiguration()
71
        );
72
        $this->assertInstanceOf(
73
            'Pagantis\OrdersApiClient\Model\Order\ShoppingCart',
74
            $order->getShoppingCart()
75
        );
76
        $this->assertInstanceOf(
77
            'Pagantis\OrdersApiClient\Model\Order\Metadata',
78
            $order->getMetadata()
79
        );
80
81
        $this->assertNull($order->getConfirmedAt());
82
        $this->assertNull($order->getCreatedAt());
83
        $this->assertNull($order->getExpiresAt());
84
        $this->assertNull($order->getRefunds());
85
    }
86
87
    /**
88
     * testImport
89
     * @throws \Exception
90
     */
91
    public function testImport()
92
    {
93
        $orderJson = file_get_contents($this->resourcePath.'Order.json');
94
        $object = json_decode($orderJson);
95
96
        foreach ($object as $key => $value) {
97
            if (null === $value) {
98
                unset($object->$key);
99
            }
100
        }
101
102
        $order = new Order();
103
        $order->import($object);
104
        $orderExport = json_decode(json_encode($order->export()));
105
        $this->assertEquals($object, $orderExport);
106
    }
107
108
    /**
109
     * testImport
110
     * @throws \Exception
111
     */
112
    public function testImportEmptyDates()
113
    {
114
        $orderJson = file_get_contents($this->resourcePath.'Order.json');
115
        $object = json_decode($orderJson);
116
117
        foreach ($object as $key => $value) {
118
            if (null === $value) {
119
                unset($object->$key);
120
            }
121
        }
122
123
        $order = new Order();
124
        $order->import($object);
125
        $orderExport = json_decode(json_encode($order->export()));
126
        $this->assertEquals($object, $orderExport);
127
    }
128
129
    /**
130
     * testConstantsNotChange
131
     */
132
    public function testConstantsNotChange()
133
    {
134
        $this->assertEquals(self::STATUS_AUTHORIZED, Order::STATUS_AUTHORIZED);
135
        $this->assertEquals(self::STATUS_CONFIRMED, Order::STATUS_CONFIRMED);
136
        $this->assertEquals(self::STATUS_CREATED, Order::STATUS_CREATED);
137
        $this->assertEquals(self::STATUS_REJECTED, Order::STATUS_REJECTED);
138
        $this->assertEquals(self::STATUS_INVALIDATED, Order::STATUS_INVALIDATED);
139
        $this->assertEquals(self::STATUS_ERROR, Order::STATUS_ERROR);
140
        $this->assertEquals(self::STATUS_UNCONFIRMED, Order::STATUS_UNCONFIRMED);
141
    }
142
}
143