1010use Magento \Customer \Api \Data \CustomerExtensionInterface ;
1111use Magento \Framework \Api \ExtensionAttributesFactory ;
1212use Magento \Newsletter \Model \ResourceModel \Subscriber ;
13+ use Magento \Store \Model \Store ;
14+ use Magento \Store \Model \StoreManagerInterface ;
1315
1416class CustomerPluginTest extends \PHPUnit \Framework \TestCase
1517{
@@ -53,6 +55,11 @@ class CustomerPluginTest extends \PHPUnit\Framework\TestCase
5355 */
5456 private $ customerMock ;
5557
58+ /**
59+ * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60+ */
61+ private $ storeManagerMock ;
62+
5663 protected function setUp ()
5764 {
5865 $ this ->subscriberFactory = $ this ->getMockBuilder (\Magento \Newsletter \Model \SubscriberFactory::class)
@@ -87,14 +94,17 @@ protected function setUp()
8794 ->setMethods (["getExtensionAttributes " ])
8895 ->disableOriginalConstructor ()
8996 ->getMockForAbstractClass ();
97+ $ this ->storeManagerMock = $ this ->createMock (StoreManagerInterface::class);
98+
9099 $ this ->subscriberFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ this ->subscriber );
91100 $ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
92101 $ this ->plugin = $ this ->objectManager ->getObject (
93102 \Magento \Newsletter \Model \Plugin \CustomerPlugin::class,
94103 [
95104 'subscriberFactory ' => $ this ->subscriberFactory ,
96105 'extensionFactory ' => $ this ->extensionFactoryMock ,
97- 'subscriberResource ' => $ this ->subscriberResourceMock
106+ 'subscriberResource ' => $ this ->subscriberResourceMock ,
107+ 'storeManager ' => $ this ->storeManagerMock ,
98108 ]
99109 );
100110 }
@@ -198,6 +208,7 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
198208 ) {
199209 $ subject = $ this ->createMock (\Magento \Customer \Api \CustomerRepositoryInterface::class);
200210 $ subscriber = [$ subscriberStatusKey => $ subscriberStatusValue ];
211+ $ this ->prepareStoreData ();
201212 $ this ->extensionFactoryMock ->expects ($ this ->any ())
202213 ->method ('create ' )
203214 ->willReturn ($ this ->customerExtensionMock );
@@ -223,6 +234,7 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
223234 {
224235 $ subject = $ this ->createMock (\Magento \Customer \Api \CustomerRepositoryInterface::class);
225236 $ subscriber = ['subscriber_id ' => 1 , 'subscriber_status ' => 1 ];
237+ $ this ->prepareStoreData ();
226238 $ this ->customerMock ->expects ($ this ->any ())
227239 ->method ('getExtensionAttributes ' )
228240 ->willReturn ($ this ->customerExtensionMock );
@@ -255,4 +267,17 @@ public function afterGetByIdDataProvider()
255267 [null , null , false ]
256268 ];
257269 }
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+ }
258283}
0 commit comments