10
10
use Magento \Customer \Api \Data \CustomerExtensionInterface ;
11
11
use Magento \Framework \Api \ExtensionAttributesFactory ;
12
12
use Magento \Newsletter \Model \ResourceModel \Subscriber ;
13
+ use Magento \Store \Model \Store ;
14
+ use Magento \Store \Model \StoreManagerInterface ;
13
15
14
16
class CustomerPluginTest extends \PHPUnit \Framework \TestCase
15
17
{
@@ -53,6 +55,11 @@ class CustomerPluginTest extends \PHPUnit\Framework\TestCase
53
55
*/
54
56
private $ customerMock ;
55
57
58
+ /**
59
+ * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60
+ */
61
+ private $ storeManagerMock ;
62
+
56
63
protected function setUp ()
57
64
{
58
65
$ this ->subscriberFactory = $ this ->getMockBuilder (\Magento \Newsletter \Model \SubscriberFactory::class)
@@ -87,6 +94,8 @@ protected function setUp()
87
94
->setMethods (['getExtensionAttributes ' ])
88
95
->disableOriginalConstructor ()
89
96
->getMockForAbstractClass ();
97
+ $ this ->storeManagerMock = $ this ->createMock (StoreManagerInterface::class);
98
+
90
99
$ this ->subscriberFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ this ->subscriber );
91
100
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
92
101
@@ -96,6 +105,7 @@ protected function setUp()
96
105
'subscriberFactory ' => $ this ->subscriberFactory ,
97
106
'extensionFactory ' => $ this ->extensionFactoryMock ,
98
107
'subscriberResource ' => $ this ->subscriberResourceMock ,
108
+ 'storeManager ' => $ this ->storeManagerMock ,
99
109
]
100
110
);
101
111
}
@@ -206,6 +216,7 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
206
216
) {
207
217
$ subject = $ this ->createMock (\Magento \Customer \Api \CustomerRepositoryInterface::class);
208
218
$ subscriber = [$ subscriberStatusKey => $ subscriberStatusValue ];
219
+ $ this ->prepareStoreData ();
209
220
210
221
$ this ->extensionFactoryMock ->expects ($ this ->any ())
211
222
->method ('create ' )
@@ -233,6 +244,7 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
233
244
{
234
245
$ subject = $ this ->createMock (\Magento \Customer \Api \CustomerRepositoryInterface::class);
235
246
$ subscriber = ['subscriber_id ' => 1 , 'subscriber_status ' => 1 ];
247
+ $ this ->prepareStoreData ();
236
248
237
249
$ this ->customerMock ->expects ($ this ->any ())
238
250
->method ('getExtensionAttributes ' )
@@ -267,4 +279,17 @@ public function afterGetByIdDataProvider()
267
279
[null , null , false ],
268
280
];
269
281
}
282
+
283
+ /**
284
+ * Prepare store information
285
+ *
286
+ * @return void
287
+ */
288
+ private function prepareStoreData ()
289
+ {
290
+ $ storeId = 1 ;
291
+ $ storeMock = $ this ->createMock (Store::class);
292
+ $ storeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ storeId );
293
+ $ this ->storeManagerMock ->expects ($ this ->any ())->method ('getStore ' )->willReturn ($ storeMock );
294
+ }
270
295
}
0 commit comments