OrderTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 36
c 1
b 0
f 0
dl 0
loc 58
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetExpiryShouldThrowUnexpectedValueException() 0 4 1
A testSetInstallmentsShouldThrowUnexpectedValueException() 0 4 1
A testCreateAndSetOrder() 0 14 1
A setUp() 0 19 1
A testSetInstallmentsWithNullShouldReturnOne() 0 5 1
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