7
7
8
8
namespace Magento \Quote \Test \Unit \Model \Quote \Item ;
9
9
10
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
11
+ use Magento \Catalog \Model \CustomOptions \CustomOptionProcessor ;
12
+ use Magento \Catalog \Model \Product ;
13
+ use Magento \Quote \Api \CartRepositoryInterface ;
14
+ use Magento \Quote \Api \Data \CartItemInterfaceFactory ;
15
+ use Magento \Quote \Model \Quote ;
16
+ use Magento \Quote \Model \Quote \Address ;
17
+ use Magento \Quote \Model \Quote \Item ;
18
+ use Magento \Quote \Model \Quote \Item \CartItemOptionsProcessor ;
19
+ use Magento \Quote \Model \Quote \Item \Repository ;
20
+ use PHPUnit \Framework \MockObject \MockObject ;
21
+
10
22
/**
11
23
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12
24
*/
13
25
class RepositoryTest extends \PHPUnit \Framework \TestCase
14
26
{
15
27
/**
16
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
28
+ * @var Repository
17
29
*/
18
- private $ objectManager ;
30
+ private $ repository ;
19
31
20
32
/**
21
- * @var \Magento\Quote\Api\CartItemRepositoryInterface
33
+ * @var CartRepositoryInterface|MockObject
22
34
*/
23
- protected $ repository ;
35
+ private $ quoteRepositoryMock ;
24
36
25
37
/**
26
- * @var \PHPUnit_Framework_MockObject_MockObject
38
+ * @var ProductRepositoryInterface|MockObject
27
39
*/
28
- protected $ quoteRepositoryMock ;
40
+ private $ productRepositoryMock ;
29
41
30
42
/**
31
- * @var \PHPUnit_Framework_MockObject_MockObject
43
+ * @var MockObject
32
44
*/
33
- protected $ productRepositoryMock ;
45
+ private $ itemMock ;
34
46
35
47
/**
36
- * @var \PHPUnit_Framework_MockObject_MockObject
48
+ * @var MockObject
37
49
*/
38
- protected $ itemMock ;
50
+ private $ quoteMock ;
39
51
40
52
/**
41
- * @var \PHPUnit_Framework_MockObject_MockObject
53
+ * @var MockObject
42
54
*/
43
- protected $ quoteMock ;
55
+ private $ productMock ;
44
56
45
57
/**
46
- * @var \PHPUnit_Framework_MockObject_MockObject
58
+ * @var MockObject
47
59
*/
48
- protected $ productMock ;
60
+ private $ quoteItemMock ;
49
61
50
62
/**
51
- * @var \PHPUnit_Framework_MockObject_MockObject
63
+ * @var CartItemInterfaceFactory|MockObject
52
64
*/
53
- protected $ quoteItemMock ;
65
+ private $ itemDataFactoryMock ;
54
66
55
67
/**
56
- * @var \PHPUnit_Framework_MockObject_MockObject
68
+ * @var CustomOptionProcessor|MockObject
57
69
*/
58
- protected $ itemDataFactoryMock ;
59
-
60
- /** @var \Magento\Catalog\Model\CustomOptions\CustomOptionProcessor|\PHPUnit_Framework_MockObject_MockObject */
61
- protected $ customOptionProcessor ;
70
+ private $ customOptionProcessor ;
62
71
63
- /** @var \PHPUnit_Framework_MockObject_MockObject */
64
- protected $ shippingAddressMock ;
72
+ /**
73
+ * @var Address|MockObject
74
+ */
75
+ private $ shippingAddressMock ;
65
76
66
77
/**
67
- * @var \PHPUnit_Framework_MockObject_MockObject
78
+ * @var CartItemOptionsProcessor|MockObject
68
79
*/
69
80
private $ optionsProcessorMock ;
70
81
@@ -73,40 +84,29 @@ class RepositoryTest extends \PHPUnit\Framework\TestCase
73
84
*/
74
85
protected function setUp ()
75
86
{
76
- $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
77
- $ this ->quoteRepositoryMock = $ this ->createMock (\Magento \Quote \Api \CartRepositoryInterface::class);
78
- $ this ->productRepositoryMock = $ this ->createMock (\Magento \Catalog \Api \ProductRepositoryInterface::class);
79
- $ this ->itemDataFactoryMock =
80
- $ this ->createPartialMock (\Magento \Quote \Api \Data \CartItemInterfaceFactory::class, ['create ' ]);
81
- $ this ->itemMock = $ this ->createMock (\Magento \Quote \Model \Quote \Item::class);
82
- $ this ->quoteMock = $ this ->createMock (\Magento \Quote \Model \Quote::class);
83
- $ this ->productMock = $ this ->createMock (\Magento \Catalog \Model \Product::class);
87
+ $ this ->quoteRepositoryMock = $ this ->createMock (CartRepositoryInterface::class);
88
+ $ this ->productRepositoryMock = $ this ->createMock (ProductRepositoryInterface::class);
89
+ $ this ->itemDataFactoryMock = $ this ->createPartialMock (CartItemInterfaceFactory::class, ['create ' ]);
90
+ $ this ->itemMock = $ this ->createMock (Item::class);
91
+ $ this ->quoteMock = $ this ->createMock (Quote::class);
92
+ $ this ->productMock = $ this ->createMock (Product::class);
84
93
$ methods = ['getId ' , 'getSku ' , 'getQty ' , 'setData ' , '__wakeUp ' , 'getProduct ' , 'addProduct ' ];
85
94
$ this ->quoteItemMock =
86
- $ this ->createPartialMock (\Magento \Quote \Model \Quote \Item::class, $ methods );
87
- $ this ->customOptionProcessor = $ this ->createMock (
88
- \Magento \Catalog \Model \CustomOptions \CustomOptionProcessor::class
89
- );
95
+ $ this ->createPartialMock (Item::class, $ methods );
96
+ $ this ->customOptionProcessor = $ this ->createMock (CustomOptionProcessor::class);
90
97
$ this ->shippingAddressMock = $ this ->createPartialMock (
91
- \ Magento \ Quote \ Model \ Quote \ Address::class,
98
+ Address::class,
92
99
['setCollectShippingRates ' ]
93
100
);
101
+ $ this ->optionsProcessorMock = $ this ->createMock (CartItemOptionsProcessor::class);
94
102
95
- $ this ->optionsProcessorMock = $ this ->createMock (
96
- \Magento \Quote \Model \Quote \Item \CartItemOptionsProcessor::class
97
- );
98
-
99
- $ this ->repository = new \Magento \Quote \Model \Quote \Item \Repository (
103
+ $ this ->repository = new Repository (
100
104
$ this ->quoteRepositoryMock ,
101
105
$ this ->productRepositoryMock ,
102
106
$ this ->itemDataFactoryMock ,
107
+ $ this ->optionsProcessorMock ,
103
108
['custom_options ' => $ this ->customOptionProcessor ]
104
109
);
105
- $ this ->objectManager ->setBackwardCompatibleProperty (
106
- $ this ->repository ,
107
- 'cartItemOptionsProcessor ' ,
108
- $ this ->optionsProcessorMock
109
- );
110
110
}
111
111
112
112
/**
@@ -118,7 +118,7 @@ public function testSave()
118
118
$ itemId = 20 ;
119
119
120
120
$ quoteMock = $ this ->createPartialMock (
121
- \ Magento \ Quote \ Model \ Quote::class,
121
+ Quote::class,
122
122
['getItems ' , 'setItems ' , 'collectTotals ' , 'getLastAddedItem ' ]
123
123
);
124
124
@@ -197,11 +197,11 @@ public function testDeleteWithCouldNotSaveException()
197
197
public function testGetList ()
198
198
{
199
199
$ productType = 'type ' ;
200
- $ quoteMock = $ this ->createMock (\ Magento \ Quote \ Model \ Quote::class);
200
+ $ quoteMock = $ this ->createMock (Quote::class);
201
201
$ this ->quoteRepositoryMock ->expects ($ this ->once ())->method ('getActive ' )
202
202
->with (33 )
203
203
->will ($ this ->returnValue ($ quoteMock ));
204
- $ itemMock = $ this ->createMock (\ Magento \ Quote \ Model \ Quote \ Item::class);
204
+ $ itemMock = $ this ->createMock (Item::class);
205
205
$ quoteMock ->expects ($ this ->once ())->method ('getAllVisibleItems ' )->will ($ this ->returnValue ([$ itemMock ]));
206
206
$ itemMock ->expects ($ this ->once ())->method ('getProductType ' )->willReturn ($ productType );
207
207
0 commit comments