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,14 +94,17 @@ 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
$ this ->plugin = $ this ->objectManager ->getObject (
93
102
\Magento \Newsletter \Model \Plugin \CustomerPlugin::class,
94
103
[
95
104
'subscriberFactory ' => $ this ->subscriberFactory ,
96
105
'extensionFactory ' => $ this ->extensionFactoryMock ,
97
- 'subscriberResource ' => $ this ->subscriberResourceMock
106
+ 'subscriberResource ' => $ this ->subscriberResourceMock ,
107
+ 'storeManager ' => $ this ->storeManagerMock ,
98
108
]
99
109
);
100
110
}
@@ -198,6 +208,7 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
198
208
) {
199
209
$ subject = $ this ->createMock (\Magento \Customer \Api \CustomerRepositoryInterface::class);
200
210
$ subscriber = [$ subscriberStatusKey => $ subscriberStatusValue ];
211
+ $ this ->prepareStoreData ();
201
212
$ this ->extensionFactoryMock ->expects ($ this ->any ())
202
213
->method ('create ' )
203
214
->willReturn ($ this ->customerExtensionMock );
@@ -223,6 +234,7 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
223
234
{
224
235
$ subject = $ this ->createMock (\Magento \Customer \Api \CustomerRepositoryInterface::class);
225
236
$ subscriber = ['subscriber_id ' => 1 , 'subscriber_status ' => 1 ];
237
+ $ this ->prepareStoreData ();
226
238
$ this ->customerMock ->expects ($ this ->any ())
227
239
->method ('getExtensionAttributes ' )
228
240
->willReturn ($ this ->customerExtensionMock );
@@ -255,4 +267,17 @@ public function afterGetByIdDataProvider()
255
267
[null , null , false ]
256
268
];
257
269
}
270
+
271
+ /**
272
+ * Prepare store information
273
+ *
274
+ * @return void
275
+ */
276
+ private function prepareStoreData ()
277
+ {
278
+ $ storeId = 1 ;
279
+ $ storeMock = $ this ->createMock (Store::class);
280
+ $ storeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ storeId );
281
+ $ this ->storeManagerMock ->expects ($ this ->any ())->method ('getStore ' )->willReturn ($ storeMock );
282
+ }
258
283
}
0 commit comments