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,6 +94,8 @@ 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
@@ -96,6 +105,7 @@ protected function setUp()
96105 'subscriberFactory ' => $ this ->subscriberFactory ,
97106 'extensionFactory ' => $ this ->extensionFactoryMock ,
98107 'subscriberResource ' => $ this ->subscriberResourceMock ,
108+ 'storeManager ' => $ this ->storeManagerMock ,
99109 ]
100110 );
101111 }
@@ -206,6 +216,7 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
206216 ) {
207217 $ subject = $ this ->createMock (\Magento \Customer \Api \CustomerRepositoryInterface::class);
208218 $ subscriber = [$ subscriberStatusKey => $ subscriberStatusValue ];
219+ $ this ->prepareStoreData ();
209220
210221 $ this ->extensionFactoryMock ->expects ($ this ->any ())
211222 ->method ('create ' )
@@ -233,6 +244,7 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
233244 {
234245 $ subject = $ this ->createMock (\Magento \Customer \Api \CustomerRepositoryInterface::class);
235246 $ subscriber = ['subscriber_id ' => 1 , 'subscriber_status ' => 1 ];
247+ $ this ->prepareStoreData ();
236248
237249 $ this ->customerMock ->expects ($ this ->any ())
238250 ->method ('getExtensionAttributes ' )
@@ -267,4 +279,17 @@ public function afterGetByIdDataProvider()
267279 [null , null , false ],
268280 ];
269281 }
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+ }
270295}
0 commit comments