34
34
class SaveTest extends TestCase
35
35
{
36
36
/** @var Save */
37
- protected $ controller ;
37
+ private $ controller ;
38
38
39
39
/** @var Context|MockObject */
40
- protected $ contextMock ;
40
+ private $ contextMock ;
41
41
42
42
/** @var Registry|MockObject */
43
- protected $ registryMock ;
43
+ private $ registryMock ;
44
44
45
45
/** @var GroupRepositoryInterface|MockObject */
46
- protected $ groupRepositoryMock ;
46
+ private $ groupRepositoryMock ;
47
47
48
48
/** @var GroupInterfaceFactory|MockObject */
49
- protected $ groupInterfaceFactoryMock ;
49
+ private $ groupInterfaceFactoryMock ;
50
50
51
51
/** @var ForwardFactory|MockObject */
52
- protected $ forwardFactoryMock ;
52
+ private $ forwardFactoryMock ;
53
53
54
54
/** @var PageFactory|MockObject */
55
- protected $ pageFactoryMock ;
55
+ private $ pageFactoryMock ;
56
56
57
57
/** @var DataObjectProcessor|MockObject */
58
- protected $ dataObjectProcessorMock ;
58
+ private $ dataObjectProcessorMock ;
59
59
60
60
/** @var RequestInterface|MockObject */
61
- protected $ request ;
61
+ private $ requestMock ;
62
62
63
63
/** @var RedirectFactory|MockObject */
64
- protected $ resultRedirectFactory ;
64
+ private $ resultRedirectFactoryMock ;
65
65
66
66
/** @var Redirect|MockObject */
67
- protected $ resultRedirect ;
67
+ private $ resultRedirectMock ;
68
68
69
69
/** @var ManagerInterface|MockObject */
70
- protected $ messageManager ;
70
+ private $ messageManagerMock ;
71
71
72
72
/** @var Forward|MockObject */
73
- protected $ resultForward ;
73
+ private $ resultForwardMock ;
74
74
75
75
/** @var GroupInterface|MockObject */
76
- protected $ group ;
76
+ private $ groupMock ;
77
77
78
78
/** @var Session|MockObject */
79
- protected $ session ;
79
+ private $ sessionMock ;
80
80
81
- /** @var GroupExtensionInterfaceFactory $groupExtensionInterfaceFactory |MockObject */
82
- private $ groupExtensionInterfaceFactory ;
81
+ /** @var GroupExtensionInterfaceFactory|MockObject $groupExtensionFactoryMock */
82
+ private $ groupExtensionFactoryMock ;
83
83
84
- /** @var GroupExtension/ MockObject */
85
- private $ groupExtension ;
84
+ /** @var GroupExtension| MockObject */
85
+ private $ groupExtensionMock ;
86
86
87
87
protected function setUp (): void
88
88
{
@@ -106,46 +106,47 @@ protected function setUp(): void
106
106
$ this ->dataObjectProcessorMock = $ this ->getMockBuilder (DataObjectProcessor::class)
107
107
->disableOriginalConstructor ()
108
108
->getMock ();
109
- $ this ->request = $ this ->getMockBuilder (RequestInterface::class)
109
+ $ this ->requestMock = $ this ->getMockBuilder (RequestInterface::class)
110
110
->getMockForAbstractClass ();
111
- $ this ->resultRedirectFactory = $ this ->getMockBuilder (RedirectFactory::class)
111
+ $ this ->resultRedirectFactoryMock = $ this ->getMockBuilder (RedirectFactory::class)
112
112
->disableOriginalConstructor ()
113
113
->getMock ();
114
- $ this ->resultRedirect = $ this ->getMockBuilder (Redirect::class)
114
+ $ this ->resultRedirectMock = $ this ->getMockBuilder (Redirect::class)
115
115
->disableOriginalConstructor ()
116
116
->getMock ();
117
- $ this ->messageManager = $ this ->getMockBuilder (ManagerInterface::class)
117
+ $ this ->messageManagerMock = $ this ->getMockBuilder (ManagerInterface::class)
118
118
->getMockForAbstractClass ();
119
- $ this ->resultForward = $ this ->getMockBuilder (Forward::class)
119
+ $ this ->resultForwardMock = $ this ->getMockBuilder (Forward::class)
120
120
->disableOriginalConstructor ()
121
121
->getMock ();
122
- $ this ->group = $ this ->getMockBuilder (GroupInterface::class)
122
+ $ this ->groupMock = $ this ->getMockBuilder (GroupInterface::class)
123
123
->setMethods (['setExtensionAttributes ' ])
124
124
->getMockForAbstractClass ();
125
- $ this ->session = $ this ->getMockBuilder (Session::class)
125
+ $ this ->sessionMock = $ this ->getMockBuilder (Session::class)
126
126
->disableOriginalConstructor ()
127
127
->setMethods (['setCustomerGroupData ' ])
128
128
->getMock ();
129
- $ this ->groupExtensionInterfaceFactory = $ this ->getMockBuilder (GroupExtensionInterfaceFactory::class)
129
+ $ this ->groupExtensionFactoryMock = $ this ->getMockBuilder (GroupExtensionInterfaceFactory::class)
130
130
->setMethods (['create ' ])
131
131
->disableOriginalConstructor ()
132
132
->getMockForAbstractClass ();
133
- $ this ->groupExtension = $ this ->getMockBuilder (GroupExtension::class)
133
+ $ this ->groupExtensionMock = $ this ->getMockBuilder (GroupExtension::class)
134
+ ->addMethods (['setExcludeWebsiteIds ' ])
134
135
->disableOriginalConstructor ()
135
136
->getMock ();
136
137
137
138
$ this ->contextMock ->expects (self ::once ())
138
139
->method ('getMessageManager ' )
139
- ->willReturn ($ this ->messageManager );
140
+ ->willReturn ($ this ->messageManagerMock );
140
141
$ this ->contextMock ->expects (self ::once ())
141
142
->method ('getRequest ' )
142
- ->willReturn ($ this ->request );
143
+ ->willReturn ($ this ->requestMock );
143
144
$ this ->contextMock ->expects (self ::once ())
144
145
->method ('getResultRedirectFactory ' )
145
- ->willReturn ($ this ->resultRedirectFactory );
146
+ ->willReturn ($ this ->resultRedirectFactoryMock );
146
147
$ this ->contextMock ->expects (self ::once ())
147
148
->method ('getSession ' )
148
- ->willReturn ($ this ->session );
149
+ ->willReturn ($ this ->sessionMock );
149
150
150
151
$ this ->controller = new Save (
151
152
$ this ->contextMock ,
@@ -155,7 +156,7 @@ protected function setUp(): void
155
156
$ this ->forwardFactoryMock ,
156
157
$ this ->pageFactoryMock ,
157
158
$ this ->dataObjectProcessorMock ,
158
- $ this ->groupExtensionInterfaceFactory
159
+ $ this ->groupExtensionFactoryMock
159
160
);
160
161
}
161
162
@@ -165,7 +166,7 @@ public function testExecuteWithTaxClassAndException(): void
165
166
$ groupId = 0 ;
166
167
$ code = 'NOT LOGGED IN ' ;
167
168
168
- $ this ->request ->method ('getParam ' )
169
+ $ this ->requestMock ->method ('getParam ' )
169
170
->willReturnMap (
170
171
[
171
172
['tax_class ' , null , $ taxClass ],
@@ -174,73 +175,73 @@ public function testExecuteWithTaxClassAndException(): void
174
175
['customer_group_excluded_websites ' , null , '' ]
175
176
]
176
177
);
177
- $ this ->groupExtensionInterfaceFactory ->expects (self ::once ())
178
+ $ this ->groupExtensionFactoryMock ->expects (self ::once ())
178
179
->method ('create ' )
179
- ->willReturn ($ this ->groupExtension );
180
- $ this ->groupExtension ->expects (self ::once ())
180
+ ->willReturn ($ this ->groupExtensionMock );
181
+ $ this ->groupExtensionMock ->expects (self ::once ())
181
182
->method ('setExcludeWebsiteIds ' )
182
183
->with ([])
183
184
->willReturnSelf ();
184
- $ this ->group ->expects (self ::once ())
185
+ $ this ->groupMock ->expects (self ::once ())
185
186
->method ('setExtensionAttributes ' )
186
- ->with ($ this ->groupExtension )
187
+ ->with ($ this ->groupExtensionMock )
187
188
->willReturnSelf ();
188
- $ this ->resultRedirectFactory ->expects ($ this ->once ())
189
+ $ this ->resultRedirectFactoryMock ->expects ($ this ->once ())
189
190
->method ('create ' )
190
- ->willReturn ($ this ->resultRedirect );
191
+ ->willReturn ($ this ->resultRedirectMock );
191
192
$ this ->groupRepositoryMock ->expects ($ this ->once ())
192
193
->method ('getById ' )
193
194
->with ($ groupId )
194
- ->willReturn ($ this ->group );
195
- $ this ->group ->expects (self ::once ())
195
+ ->willReturn ($ this ->groupMock );
196
+ $ this ->groupMock ->expects (self ::once ())
196
197
->method ('getCode ' )
197
198
->willReturn ($ code );
198
- $ this ->group ->expects (self ::once ())
199
+ $ this ->groupMock ->expects (self ::once ())
199
200
->method ('setCode ' )
200
201
->with ($ code );
201
- $ this ->group ->expects (self ::once ())
202
+ $ this ->groupMock ->expects (self ::once ())
202
203
->method ('setTaxClassId ' )
203
204
->with ($ taxClass );
204
205
$ this ->groupRepositoryMock ->expects (self ::once ())
205
206
->method ('save ' )
206
- ->with ($ this ->group );
207
- $ this ->messageManager ->expects (self ::once ())
207
+ ->with ($ this ->groupMock );
208
+ $ this ->messageManagerMock ->expects (self ::once ())
208
209
->method ('addSuccessMessage ' )
209
210
->with (__ ('You saved the customer group. ' ));
210
211
$ exception = new \Exception ('Exception ' );
211
- $ this ->resultRedirect ->expects (self ::at (0 ))
212
+ $ this ->resultRedirectMock ->expects (self ::at (0 ))
212
213
->method ('setPath ' )
213
214
->with ('customer/group ' )
214
215
->willThrowException ($ exception );
215
- $ this ->messageManager ->expects (self ::once ())
216
+ $ this ->messageManagerMock ->expects (self ::once ())
216
217
->method ('addErrorMessage ' )
217
218
->with ('Exception ' );
218
219
$ this ->dataObjectProcessorMock ->expects (self ::once ())
219
220
->method ('buildOutputDataArray ' )
220
- ->with ($ this ->group , GroupInterface::class)
221
+ ->with ($ this ->groupMock , GroupInterface::class)
221
222
->willReturn (['code ' => $ code ]);
222
- $ this ->session ->expects (self ::once ())
223
+ $ this ->sessionMock ->expects (self ::once ())
223
224
->method ('setCustomerGroupData ' )
224
225
->with (['customer_group_code ' => $ code ]);
225
- $ this ->resultRedirect ->expects (self ::at (1 ))
226
+ $ this ->resultRedirectMock ->expects (self ::at (1 ))
226
227
->method ('setPath ' )
227
228
->with ('customer/group/edit ' , ['id ' => $ groupId ]);
228
- self ::assertSame ($ this ->resultRedirect , $ this ->controller ->execute ());
229
+ self ::assertSame ($ this ->resultRedirectMock , $ this ->controller ->execute ());
229
230
}
230
231
231
232
public function testExecuteWithoutTaxClass (): void
232
233
{
233
- $ this ->request ->expects (self ::once ())
234
+ $ this ->requestMock ->expects (self ::once ())
234
235
->method ('getParam ' )
235
236
->with ('tax_class ' )
236
237
->willReturn (null );
237
238
$ this ->forwardFactoryMock ->expects (self ::once ())
238
239
->method ('create ' )
239
- ->willReturn ($ this ->resultForward );
240
- $ this ->resultForward ->expects (self ::once ())
240
+ ->willReturn ($ this ->resultForwardMock );
241
+ $ this ->resultForwardMock ->expects (self ::once ())
241
242
->method ('forward ' )
242
243
->with ('new ' )
243
244
->willReturnSelf ();
244
- self ::assertSame ($ this ->resultForward , $ this ->controller ->execute ());
245
+ self ::assertSame ($ this ->resultForwardMock , $ this ->controller ->execute ());
245
246
}
246
247
}
0 commit comments