1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Plane\Shop\Tests; |
4
|
|
|
|
5
|
|
|
use Plane\Shop\CartItem; |
6
|
|
|
use OutOfBoundsException; |
7
|
|
|
use Plane\Shop\CartPresenter; |
8
|
|
|
use Plane\Shop\PaymentInterface; |
9
|
|
|
use Plane\Shop\ShippingInterface; |
10
|
|
|
use Plane\Shop\Discount\TotalPriceThresholdDiscount; |
11
|
|
|
|
12
|
|
|
class CartPresenterTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
use MoneyTrait; |
15
|
|
|
use CartTrait; |
16
|
|
|
|
17
|
|
|
const CURRENCY = 'USD'; |
18
|
|
|
|
19
|
|
|
protected $cartPresenter; |
20
|
|
|
|
21
|
|
|
protected function setUp(): void |
22
|
|
|
{ |
23
|
|
|
$this->createFirstCartItem(); |
24
|
|
|
$this->createSecondCartItem(); |
25
|
|
|
$this->createCart(); |
26
|
|
|
|
27
|
|
|
$this->cartPresenter = new CartPresenter($this->cart); |
28
|
|
|
$this->cartPresenter->setShipping($this->getShippingMock()); |
29
|
|
|
$this->cartPresenter->setPayment($this->getPaymentMock()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetCurrency() |
33
|
|
|
{ |
34
|
|
|
$this->assertSame(self::CURRENCY, $this->cartPresenter->getCurrency()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGetShipping() |
38
|
|
|
{ |
39
|
|
|
$this->assertInstanceOf(ShippingInterface::class, $this->cartPresenter->getShipping()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testGetPayment() |
43
|
|
|
{ |
44
|
|
|
$this->assertInstanceOf(PaymentInterface::class, $this->cartPresenter->getPayment()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGet() |
48
|
|
|
{ |
49
|
|
|
$this->assertSame($this->secondCartItem, $this->cartPresenter->get($this->secondCartItem->getId())); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testFailedGet() |
53
|
|
|
{ |
54
|
|
|
$this->expectException(OutOfBoundsException::class); |
55
|
|
|
|
56
|
|
|
$this->cartPresenter->get('4'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testHas() |
60
|
|
|
{ |
61
|
|
|
$this->assertTrue($this->cartPresenter->has('1')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testFailedHas() |
65
|
|
|
{ |
66
|
|
|
$this->assertFalse($this->cartPresenter->has('4')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testUpdate() |
70
|
|
|
{ |
71
|
|
|
$firstAltered = $this->createMock(CartItem::class); |
72
|
|
|
$firstAltered->method('getId')->willReturn(1); |
|
|
|
|
73
|
|
|
$firstAltered->method('getQuantity')->willReturn(5); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$this->assertTrue($this->cartPresenter->itemsQuantity() == 3); |
76
|
|
|
|
77
|
|
|
$this->cartPresenter->update($firstAltered); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$this->assertTrue($this->cartPresenter->itemsQuantity() == 7); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function testRemove() |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$this->cartPresenter->remove($this->firstCartItem->getId()); |
85
|
|
|
|
86
|
|
|
$this->assertSame([ |
87
|
|
|
2 => $this->secondCartItem |
88
|
|
|
], $this->cartPresenter->items()); |
89
|
|
|
|
90
|
|
|
$this->assertTrue(count($this->cartPresenter->items()) == 1); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testFailedRemove() |
94
|
|
|
{ |
95
|
|
|
$this->expectException(OutOfBoundsException::class); |
96
|
|
|
|
97
|
|
|
$this->cartPresenter->remove('3'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
View Code Duplication |
public function testClear() |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$this->cartPresenter->clear(); |
103
|
|
|
|
104
|
|
|
$this->assertSame([], $this->cartPresenter->items()); |
105
|
|
|
$this->assertTrue(count($this->cartPresenter->items()) == 0); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testToArray() |
109
|
|
|
{ |
110
|
|
|
$discount = $this->createMock(TotalPriceThresholdDiscount::class); |
111
|
|
|
$discount->method('getDescription')->willReturn('Test discount'); |
|
|
|
|
112
|
|
|
$discount->method('getPriceAfterDiscount')->willReturn($this->getMoney('5')); |
|
|
|
|
113
|
|
|
|
114
|
|
|
$this->cart->addDiscount($discount); |
|
|
|
|
115
|
|
|
|
116
|
|
|
$cartPresenter = new CartPresenter($this->cart); |
117
|
|
|
|
118
|
|
|
$this->assertTrue(is_array($cartPresenter->toArray())); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testDecoratorMethods() |
122
|
|
|
{ |
123
|
|
|
$cartPresenter = new CartPresenter($this->cart); |
124
|
|
|
|
125
|
|
|
$this->assertSame($cartPresenter->totalNet(), $this->getAmount($this->cart->totalNet())); |
126
|
|
|
$this->assertSame($cartPresenter->totalGross(), $this->getAmount($this->cart->totalGross())); |
127
|
|
|
$this->assertSame($cartPresenter->tax(), $this->getAmount($this->cart->tax())); |
128
|
|
|
$this->assertSame($cartPresenter->totalAfterDiscounts(), $this->getAmount($this->cart->totalAfterDiscounts())); |
129
|
|
|
$this->assertSame($cartPresenter->shippingCost(), $this->getAmount($this->cart->shippingCost())); |
130
|
|
|
$this->assertSame($cartPresenter->paymentFee(), $this->getAmount($this->cart->paymentFee())); |
131
|
|
|
} |
132
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.