Passed
Branch refactoring (232535)
by João Felipe Magro
01:20
created

OrderTest::testCreateAndSetOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
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
            ->setFingerPrint('ABCD123456789')
23
            ->setOperation(\Ipag\Classes\Enum\Operation::PAYMENT)
24
            ->setPayment(new \Ipag\Classes\Payment())
25
            ->setCustomer(new \Ipag\Classes\Customer())
26
            ->setCart(new \Ipag\Classes\Cart())
27
            ->setSubscription(new \Ipag\Classes\Subscription());
28
    }
29
30
    public function testCreateAndSetOrder()
31
    {
32
        $this->assertEquals('123456', $this->order->getOrderId());
33
        $this->assertEquals('https://minha_loja.com.br/ipag/callback', $this->order->getCallbackUrl());
34
        $this->assertEquals(10.85, $this->order->getAmount());
35
        $this->assertEquals(12, $this->order->getInstallments());
36
        $this->assertEquals('10/10/2018', $this->order->getExpiry());
37
        $this->assertEquals('ABCD123456789', $this->order->getFingerPrint());
38
        $this->assertEquals(\Ipag\Classes\Enum\Operation::PAYMENT, $this->order->getOperation());
39
        $this->assertInstanceOf(\Ipag\Classes\Payment::class, $this->order->getPayment());
40
        $this->assertInstanceOf(\Ipag\Classes\Customer::class, $this->order->getCustomer());
41
        $this->assertInstanceOf(\Ipag\Classes\Cart::class, $this->order->getCart());
42
        $this->assertInstanceOf(\Ipag\Classes\Subscription::class, $this->order->getSubscription());
43
    }
44
45
    public function testSetExpiryShouldThrowUnexpectedValueException()
46
    {
47
        $this->expectException(\UnexpectedValueException::class);
48
        $this->order->setExpiry('2018-10-10');
49
    }
50
51
    public function testSetInstallmentsShouldThrowUnexpectedValueException()
52
    {
53
        $this->expectException(\UnexpectedValueException::class);
54
        $this->order->setInstallments(48);
55
    }
56
57
    public function testSetInstallmentsWithNullShouldReturnOne()
58
    {
59
        $this->order->setInstallments(null);
60
61
        $this->assertEquals(1, $this->order->getInstallments());
62
    }
63
}
64