Completed
Pull Request — master (#42)
by
unknown
02:42
created

OrdersTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 7
c 3
b 0
f 1
lcom 1
cbo 2
dl 0
loc 69
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A executeOrder() 0 12 3
A testCreateOrder() 0 7 1
A testItens() 0 7 1
A testTotal() 0 7 1
A testTotalConstant() 0 9 1
1
<?php
2
3
namespace Moip\Tests\Resource;
4
5
use Moip\Resource\Orders;
6
use Moip\Tests\MoipTestCase;
7
8
class OrdersTest extends MoipTestCase
9
{
10
    /**
11
     * Send http request.
12
     *
13
     * @param Orders $order
14
     * @param string $body
15
     *
16
     * @return Orders
17
     */
18
    private function executeOrder(Orders $order = null, $body = null)
19
    {
20
        if (empty($body)) {
21
            $body = $this->body_order;
22
        }
23
        if (empty($order)) {
24
            $order = $this->createOrder();
25
        }
26
        $this->mockHttpSession($body);
27
28
        return $order->create();
29
    }
30
31
    /**
32
     * Test creating an order.
33
     */
34
    public function testCreateOrder()
35
    {
36
        $order_created = $this->executeOrder();
37
38
        $this->assertEquals($this->last_ord_id, $order_created->getOwnId());
39
        $this->assertEquals('CREATED', $order_created->getStatus());
40
    }
41
42
    /**
43
     * Teste if created itens price is correct.
44
     */
45
    public function testItens()
46
    {
47
        $order_created = $this->executeOrder();
48
        $itens = $order_created->getItemIterator()->getArrayCopy();
49
        $this->assertEquals(100000, $itens[0]->price);
50
        $this->assertEquals(990, $itens[1]->price);
51
    }
52
53
    /**
54
     *Test if the total is correct.
55
     */
56
    public function testTotal()
57
    {
58
        $order = $this->executeOrder();
59
60
        $total = $order->getSubtotalItems() + $order->getSubtotalShipping() + $order->getSubtotalAddition() - $order->getSubtotalDiscount();
61
        $this->assertEquals($total, $order->getAmountTotal());
62
    }
63
64
    /**
65
     * Test if the total is equal to the expected total.
66
     */
67
    public function testTotalConstant()
68
    {
69
        $order = $this->executeOrder();
70
        $expected = (100000 + 2 * 990 + 1490) - 1000;
71
        $total_calculated = $total = $order->getSubtotalItems() + $order->getSubtotalShipping() + $order->getSubtotalAddition() - $order->getSubtotalDiscount();
0 ignored issues
show
Unused Code introduced by
$total is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
72
73
        $this->assertEquals($expected, $total_calculated);
74
        $this->assertEquals($expected, $order->getAmountTotal());
75
    }
76
}
77