1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2014 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
18
18
use Magento \Customer \Model \Metadata \FormFactory ;
19
19
use Magento \Framework \Api \DataObjectHelper ;
20
20
use Magento \Framework \App \RequestInterface ;
21
+ use Magento \Framework \Exception \LocalizedException ;
22
+ use Magento \Framework \Message \ManagerInterface ;
23
+ use Magento \Framework \ObjectManagerInterface ;
21
24
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
22
25
use Magento \Quote \Api \CartRepositoryInterface ;
23
26
use Magento \Quote \Model \Quote ;
@@ -44,57 +47,67 @@ class CreateTest extends TestCase
44
47
/**
45
48
* @var Create
46
49
*/
47
- private $ adminOrderCreate ;
50
+ private Create $ adminOrderCreate ;
48
51
49
52
/**
50
53
* @var CartRepositoryInterface|MockObject
51
54
*/
52
- private $ quoteRepository ;
55
+ private CartRepositoryInterface $ quoteRepository ;
53
56
54
57
/**
55
58
* @var QuoteFactory|MockObject
56
59
*/
57
- private $ quoteFactory ;
60
+ private QuoteFactory $ quoteFactory ;
58
61
59
62
/**
60
63
* @var SessionQuote|MockObject
61
64
*/
62
- private $ sessionQuote ;
65
+ private SessionQuote $ sessionQuote ;
63
66
64
67
/**
65
68
* @var FormFactory|MockObject
66
69
*/
67
- private $ formFactory ;
70
+ private FormFactory $ formFactory ;
68
71
69
72
/**
70
73
* @var CustomerInterfaceFactory|MockObject
71
74
*/
72
- private $ customerFactory ;
75
+ private CustomerInterfaceFactory $ customerFactory ;
73
76
74
77
/**
75
78
* @var Updater|MockObject
76
79
*/
77
- private $ itemUpdater ;
80
+ private Updater $ itemUpdater ;
78
81
79
82
/**
80
83
* @var Mapper|MockObject
81
84
*/
82
- private $ customerMapper ;
85
+ private Mapper $ customerMapper ;
83
86
84
87
/**
85
88
* @var GroupRepositoryInterface|MockObject
86
89
*/
87
- private $ groupRepository ;
90
+ private GroupRepositoryInterface $ groupRepository ;
88
91
89
92
/**
90
93
* @var DataObjectHelper|MockObject
91
94
*/
92
- private $ dataObjectHelper ;
95
+ private DataObjectHelper $ dataObjectHelper ;
93
96
94
97
/**
95
98
* @var Order|MockObject
96
99
*/
97
- private $ orderMock ;
100
+ private Order $ orderMock ;
101
+
102
+ /**
103
+ * @var ObjectManagerInterface|ObjectManagerInterface&MockObject|MockObject
104
+ */
105
+ private ObjectManagerInterface $ objectManager ;
106
+
107
+ /**
108
+ * @var ManagerInterface|ManagerInterface&MockObject|MockObject
109
+ */
110
+ private ManagerInterface $ messageManager ;
98
111
99
112
/**
100
113
* @inheritdoc
@@ -166,10 +179,14 @@ protected function setUp(): void
166
179
)
167
180
->getMock ();
168
181
182
+ $ this ->objectManager = $ this ->createMock (ObjectManagerInterface::class);
183
+ $ this ->messageManager = $ this ->createMock (ManagerInterface::class);
169
184
$ objectManagerHelper = new ObjectManagerHelper ($ this );
170
185
$ this ->adminOrderCreate = $ objectManagerHelper ->getObject (
171
186
Create::class,
172
187
[
188
+ '_objectManager ' => $ this ->objectManager ,
189
+ 'messageManager ' => $ this ->messageManager ,
173
190
'quoteSession ' => $ this ->sessionQuote ,
174
191
'metadataFormFactory ' => $ this ->formFactory ,
175
192
'customerFactory ' => $ this ->customerFactory ,
@@ -183,6 +200,46 @@ protected function setUp(): void
183
200
);
184
201
}
185
202
203
+ /**
204
+ * @return void
205
+ * @throws \PHPUnit\Framework\MockObject\Exception|LocalizedException
206
+ */
207
+ public function testInitFromOrderItemNoExceptionThrownOnAddProduct (): void
208
+ {
209
+ $ orderItemId = $ productId = 1 ;
210
+ $ exceptionMessage = 'Exception message ' ;
211
+
212
+ $ buyRequest = $ this ->createMock (\Magento \Framework \DataObject::class);
213
+
214
+ $ orderItem = $ this ->createMock (\Magento \Sales \Model \Order \Item::class);
215
+ $ orderItem ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ orderItemId );
216
+ $ orderItem ->expects ($ this ->once ())->method ('getProductId ' )->willReturn ($ productId );
217
+ $ orderItem ->expects ($ this ->once ())->method ('getBuyRequest ' )->willReturn ($ buyRequest );
218
+ $ orderItem ->expects ($ this ->once ())->method ('getProductOptions ' )->willReturn (null );
219
+
220
+ $ product = $ this ->createMock (\Magento \Catalog \Model \Product::class);
221
+ $ product ->expects ($ this ->once ())->method ('setStoreId ' )->willReturnSelf ();
222
+ $ product ->expects ($ this ->once ())->method ('load ' )->willReturnSelf ();
223
+ $ product ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ productId );
224
+ $ this ->objectManager ->expects ($ this ->once ())->method ('create ' )->willReturn ($ product );
225
+
226
+ $ exception = new LocalizedException (__ ($ exceptionMessage ));
227
+ $ quote = $ this ->createMock (Quote::class);
228
+ $ quote ->expects ($ this ->once ())
229
+ ->method ('addProduct ' )
230
+ ->with ($ product , $ buyRequest )
231
+ ->willThrowException ($ exception );
232
+ $ this ->sessionQuote ->method ('getQuote ' )
233
+ ->willReturn ($ quote );
234
+
235
+ $ this ->messageManager ->expects ($ this ->once ())
236
+ ->method ('addErrorMessage ' )
237
+ ->with (__ ($ exceptionMessage ))
238
+ ->willReturnSelf ();
239
+
240
+ $ this ->adminOrderCreate ->initFromOrderItem ($ orderItem );
241
+ }
242
+
186
243
public function testSetAccountData ()
187
244
{
188
245
$ taxClassId = 1 ;
0 commit comments