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(); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$this->assertEquals($expected, $total_calculated); |
74
|
|
|
$this->assertEquals($expected, $order->getAmountTotal()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.