Skip to content

Commit c5c060f

Browse files
author
Joan He
committed
Merge remote-tracking branch 'trigger/MAGETWO-98377' into pr
2 parents b7a8fad + c3e79e2 commit c5c060f

File tree

2 files changed

+4
-40
lines changed

2 files changed

+4
-40
lines changed

app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
namespace Magento\Newsletter\Model\Plugin;
77

88
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
9-
use Magento\Customer\Api\Data\CustomerExtensionInterface;
109
use Magento\Customer\Api\Data\CustomerInterface;
10+
use Magento\Newsletter\Model\SubscriberFactory;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
12-
use Magento\Framework\App\ObjectManager;
1312
use Magento\Newsletter\Model\ResourceModel\Subscriber;
14-
use Magento\Newsletter\Model\SubscriberFactory;
15-
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Customer\Api\Data\CustomerExtensionInterface;
1614

1715
/**
1816
* Newsletter Plugin for customer
@@ -41,29 +39,21 @@ class CustomerPlugin
4139
*/
4240
private $customerSubscriptionStatus = [];
4341

44-
/**
45-
* @var StoreManagerInterface
46-
*/
47-
private $storeManager;
48-
4942
/**
5043
* Initialize dependencies.
5144
*
5245
* @param SubscriberFactory $subscriberFactory
5346
* @param ExtensionAttributesFactory $extensionFactory
5447
* @param Subscriber $subscriberResource
55-
* @param StoreManagerInterface|null $storeManager
5648
*/
5749
public function __construct(
5850
SubscriberFactory $subscriberFactory,
5951
ExtensionAttributesFactory $extensionFactory,
60-
Subscriber $subscriberResource,
61-
StoreManagerInterface $storeManager = null
52+
Subscriber $subscriberResource
6253
) {
6354
$this->subscriberFactory = $subscriberFactory;
6455
$this->extensionFactory = $extensionFactory;
6556
$this->subscriberResource = $subscriberResource;
66-
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
6757
}
6858

6959
/**
@@ -164,8 +154,7 @@ public function afterDelete(CustomerRepository $subject, $result, CustomerInterf
164154
public function afterGetById(CustomerRepository $subject, CustomerInterface $customer)
165155
{
166156
$extensionAttributes = $customer->getExtensionAttributes();
167-
$storeId = $this->storeManager->getStore()->getId();
168-
$customer->setStoreId($storeId);
157+
169158
if ($extensionAttributes === null) {
170159
/** @var CustomerExtensionInterface $extensionAttributes */
171160
$extensionAttributes = $this->extensionFactory->create(CustomerInterface::class);

app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use Magento\Customer\Api\Data\CustomerExtensionInterface;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
1212
use Magento\Newsletter\Model\ResourceModel\Subscriber;
13-
use Magento\Store\Model\Store;
14-
use Magento\Store\Model\StoreManagerInterface;
1513

1614
class CustomerPluginTest extends \PHPUnit\Framework\TestCase
1715
{
@@ -55,11 +53,6 @@ class CustomerPluginTest extends \PHPUnit\Framework\TestCase
5553
*/
5654
private $customerMock;
5755

58-
/**
59-
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60-
*/
61-
private $storeManagerMock;
62-
6356
protected function setUp()
6457
{
6558
$this->subscriberFactory = $this->getMockBuilder(\Magento\Newsletter\Model\SubscriberFactory::class)
@@ -94,8 +87,6 @@ protected function setUp()
9487
->setMethods(['getExtensionAttributes'])
9588
->disableOriginalConstructor()
9689
->getMockForAbstractClass();
97-
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
98-
9990
$this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber);
10091
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
10192

@@ -105,7 +96,6 @@ protected function setUp()
10596
'subscriberFactory' => $this->subscriberFactory,
10697
'extensionFactory' => $this->extensionFactoryMock,
10798
'subscriberResource' => $this->subscriberResourceMock,
108-
'storeManager' => $this->storeManagerMock,
10999
]
110100
);
111101
}
@@ -216,7 +206,6 @@ public function testAfterGetByIdCreatesExtensionAttributesIfItIsNotSet(
216206
) {
217207
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
218208
$subscriber = [$subscriberStatusKey => $subscriberStatusValue];
219-
$this->prepareStoreData();
220209

221210
$this->extensionFactoryMock->expects($this->any())
222211
->method('create')
@@ -244,7 +233,6 @@ public function testAfterGetByIdSetsIsSubscribedFlagIfItIsNotSet()
244233
{
245234
$subject = $this->createMock(\Magento\Customer\Api\CustomerRepositoryInterface::class);
246235
$subscriber = ['subscriber_id' => 1, 'subscriber_status' => 1];
247-
$this->prepareStoreData();
248236

249237
$this->customerMock->expects($this->any())
250238
->method('getExtensionAttributes')
@@ -279,17 +267,4 @@ public function afterGetByIdDataProvider()
279267
[null, null, false],
280268
];
281269
}
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-
}
295270
}

0 commit comments

Comments
 (0)