OrderTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 19
rs 9.7333
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\Classes;
4
5
use Ipag\Classes\Order;
6
use PHPUnit\Framework\TestCase;
7
8
class OrderTest extends TestCase
9
{
10
    private $order;
11
12
    public function setUp()
13
    {
14
        parent::setUp();
15
16
        $this->order = (new Order())
17
            ->setOrderId('123456')
18
            ->setCallbackUrl('https://minha_loja.com.br/ipag/callback')
19
            ->setAmount(10.85)
20
            ->setInstallments(12)
21
            ->setExpiry('10/10/2018')
22
            ->setIp('192.168.0.100')
23
            ->setFingerPrint('ABCD123456789')
24
            ->setAcquirerToken('QWERTY987654321')
25
            ->setAntifraud(0)
26
            ->setOperation(\Ipag\Classes\Enum\Operation::PAYMENT)
27
            ->setPayment(new \Ipag\Classes\Payment())
28
            ->setCustomer(new \Ipag\Classes\Customer())
29
            ->setCart(new \Ipag\Classes\Cart())
30
            ->setSubscription(new \Ipag\Classes\Subscription());
31
    }
32
33
    public function testCreateAndSetOrder()
34
    {
35
        $this->assertEquals('123456', $this->order->getOrderId());
36
        $this->assertEquals('https://minha_loja.com.br/ipag/callback', $this->order->getCallbackUrl());
37
        $this->assertEquals(10.85, $this->order->getAmount());
38
        $this->assertEquals(12, $this->order->getInstallments());
39
        $this->assertEquals('10/10/2018', $this->order->getExpiry());
40
        $this->assertEquals('ABCD123456789', $this->order->getFingerPrint());
41
        $this->assertEquals('QWERTY987654321', $this->order->getAcquirerToken());
42
        $this->assertEquals(\Ipag\Classes\Enum\Operation::PAYMENT, $this->order->getOperation());
43
        $this->assertInstanceOf(\Ipag\Classes\Payment::class, $this->order->getPayment());
44
        $this->assertInstanceOf(\Ipag\Classes\Customer::class, $this->order->getCustomer());
45
        $this->assertInstanceOf(\Ipag\Classes\Cart::class, $this->order->getCart());
46
        $this->assertInstanceOf(\Ipag\Classes\Subscription::class, $this->order->getSubscription());
47
    }
48
49
    public function testSetExpiryShouldThrowUnexpectedValueException()
50
    {
51
        $this->expectException(\UnexpectedValueException::class);
52
        $this->order->setExpiry('2018-10-10');
53
    }
54
55
    public function testSetInstallmentsShouldThrowUnexpectedValueException()
56
    {
57
        $this->expectException(\UnexpectedValueException::class);
58
        $this->order->setInstallments(48);
59
    }
60
61
    public function testSetInstallmentsWithNullShouldReturnOne()
62
    {
63
        $this->order->setInstallments(null);
64
65
        $this->assertEquals(1, $this->order->getInstallments());
66
    }
67
}
68