Skip to content

Commit 4e5c323

Browse files
Merge remote-tracking branch 'origin/AC-15102' into AC-15050
2 parents 60d6b96 + 6af1f47 commit 4e5c323

File tree

204 files changed

+3040
-3973
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

204 files changed

+3040
-3973
lines changed

app/code/Magento/Customer/Model/Customer/Attribute/Source/Website.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ class Website extends \Magento\Eav\Model\Entity\Attribute\Source\Table
1818
/**
1919
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
2020
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
21+
* @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
2122
* @param \Magento\Store\Model\System\Store $store
2223
*/
2324
public function __construct(
2425
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory,
2526
\Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory,
27+
?\Magento\Store\Model\StoreManagerInterface $storeManager,
2628
\Magento\Store\Model\System\Store $store
2729
) {
28-
parent::__construct($attrOptionCollectionFactory, $attrOptionFactory);
30+
parent::__construct($attrOptionCollectionFactory, $attrOptionFactory, $storeManager);
2931
$this->_store = $store;
3032
}
3133

app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/CountryWithWebsites.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function __construct(
9191
?? ObjectManager::getInstance()->get(Http::class);
9292
$this->customerRepository = $customerRepository
9393
?? ObjectManager::getInstance()->get(CustomerRepositoryInterface::class);
94-
parent::__construct($attrOptionCollectionFactory, $attrOptionFactory);
94+
parent::__construct($attrOptionCollectionFactory, $attrOptionFactory, $storeManager);
9595
}
9696

9797
/**

app/code/Magento/Customer/Test/Unit/Block/Account/AuthenticationPopupTest.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616
use Magento\Framework\View\Element\Template\Context;
1717
use Magento\Store\Api\Data\StoreInterface;
1818
use Magento\Store\Model\ScopeInterface;
19+
use Magento\Store\Model\Store;
1920
use Magento\Store\Model\StoreManagerInterface;
21+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
22+
use PHPUnit\Framework\Attributes\DataProvider;
2023
use PHPUnit\Framework\Exception;
2124
use PHPUnit\Framework\MockObject\MockObject;
2225
use PHPUnit\Framework\TestCase;
2326

2427
class AuthenticationPopupTest extends TestCase
2528
{
29+
use MockCreationTrait;
30+
2631
/** @var AuthenticationPopup */
2732
private $model;
2833

@@ -99,30 +104,24 @@ function ($string) {
99104
* @param string $forgotUrl
100105
* @param array $result
101106
* @throws Exception
102-
*
103-
* @dataProvider dataProviderGetConfig
104107
*/
108+
#[DataProvider('dataProviderGetConfig')]
105109
public function testGetConfig($isAutocomplete, $baseUrl, $registerUrl, $forgotUrl, $loginUrl, array $result)
106110
{
107111
$this->scopeConfigMock->expects($this->any())
108112
->method('getValue')
109113
->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE, null)
110114
->willReturn($isAutocomplete);
111115

112-
/** @var StoreInterface||\PHPUnit\Framework\MockObject\MockObject $storeMock */
113-
$storeMock = $this->getMockBuilder(StoreInterface::class)
114-
->addMethods(['getBaseUrl'])
115-
->getMockForAbstractClass();
116+
/** @var Store||\PHPUnit\Framework\MockObject\MockObject $storeMock */
117+
$storeMock = $this->createPartialMock(Store::class, ['getBaseUrl']);
118+
$storeMock->method('getBaseUrl')->willReturn($baseUrl);
116119

117120
$this->storeManagerMock->expects($this->any())
118121
->method('getStore')
119122
->with(null)
120123
->willReturn($storeMock);
121124

122-
$storeMock->expects($this->any())
123-
->method('getBaseUrl')
124-
->willReturn($baseUrl);
125-
126125
$this->urlBuilderMock->expects($this->any())
127126
->method('getUrl')
128127
->willReturnMap(
@@ -208,9 +207,8 @@ public static function dataProviderGetConfig()
208207
* @param string $forgotUrl
209208
* @param array $result
210209
* @throws Exception
211-
*
212-
* @dataProvider dataProviderGetConfig
213210
*/
211+
#[DataProvider('dataProviderGetConfig')]
214212
public function testGetSerializedConfig(
215213
$isAutocomplete,
216214
$baseUrl,
@@ -224,20 +222,15 @@ public function testGetSerializedConfig(
224222
->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE, null)
225223
->willReturn($isAutocomplete);
226224

227-
/** @var StoreInterface||\PHPUnit\Framework\MockObject\MockObject $storeMock */
228-
$storeMock = $this->getMockBuilder(StoreInterface::class)
229-
->addMethods(['getBaseUrl'])
230-
->getMockForAbstractClass();
225+
/** @var Store||\PHPUnit\Framework\MockObject\MockObject $storeMock */
226+
$storeMock = $this->createPartialMock(Store::class, ['getBaseUrl']);
227+
$storeMock->method('getBaseUrl')->willReturn($baseUrl);
231228

232229
$this->storeManagerMock->expects($this->any())
233230
->method('getStore')
234231
->with(null)
235232
->willReturn($storeMock);
236233

237-
$storeMock->expects($this->any())
238-
->method('getBaseUrl')
239-
->willReturn($baseUrl);
240-
241234
$this->urlBuilderMock->expects($this->any())
242235
->method('getUrl')
243236
->willReturnMap(

app/code/Magento/Customer/Test/Unit/Block/Account/CustomerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Customer\Block\Account\Customer;
1111
use Magento\Framework\App\Http\Context;
1212
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1314
use PHPUnit\Framework\MockObject\MockObject;
1415
use PHPUnit\Framework\TestCase;
1516

@@ -44,9 +45,8 @@ public static function customerLoggedInDataProvider()
4445

4546
/**
4647
* @param $isLoggedIn
47-
* @param $result
48-
* @dataProvider customerLoggedInDataProvider
49-
*/
48+
* @param $result */
49+
#[DataProvider('customerLoggedInDataProvider')]
5050
public function testCustomerLoggedIn($isLoggedIn, $result)
5151
{
5252
$this->httpContext->expects($this->once())->method('getValue')

app/code/Magento/Customer/Test/Unit/Block/Account/Dashboard/InfoTest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\View\LayoutInterface;
2020
use Magento\Newsletter\Model\Subscriber;
2121
use Magento\Newsletter\Model\SubscriberFactory;
22+
use PHPUnit\Framework\Attributes\DataProvider;
2223
use PHPUnit\Framework\MockObject\MockObject;
2324
use PHPUnit\Framework\TestCase;
2425

@@ -29,11 +30,11 @@
2930
class InfoTest extends TestCase
3031
{
3132
/** Constant values used for testing */
32-
const CUSTOMER_ID = 1;
33+
private const CUSTOMER_ID = 1;
3334

34-
const CHANGE_PASSWORD_URL = 'http://localhost/index.php/account/edit/changepass/1';
35+
private const CHANGE_PASSWORD_URL = 'http://localhost/index.php/account/edit/changepass/1';
3536

36-
const EMAIL_ADDRESS = 'john.doe@example.com';
37+
private const EMAIL_ADDRESS = 'john.doe@example.com';
3738

3839
/** @var MockObject|Context */
3940
private $_context;
@@ -70,10 +71,10 @@ protected function setUp(): void
7071
{
7172
$this->currentCustomer = $this->createMock(CurrentCustomer::class);
7273

73-
$urlBuilder = $this->getMockForAbstractClass(UrlInterface::class, [], '', false);
74+
$urlBuilder = $this->createMock(UrlInterface::class);
7475
$urlBuilder->expects($this->any())->method('getUrl')->willReturn(self::CHANGE_PASSWORD_URL);
7576

76-
$layout = $this->getMockForAbstractClass(LayoutInterface::class, [], '', false);
77+
$layout = $this->createMock(LayoutInterface::class);
7778
$this->_formRegister = $this->createMock(Register::class);
7879
$layout->expects($this->any())
7980
->method('getBlockSingleton')
@@ -89,7 +90,7 @@ protected function setUp(): void
8990
$this->_customerSession = $this->createMock(Session::class);
9091
$this->_customerSession->expects($this->any())->method('getId')->willReturn(self::CUSTOMER_ID);
9192

92-
$this->_customer = $this->getMockForAbstractClass(CustomerInterface::class);
93+
$this->_customer = $this->createMock(CustomerInterface::class);
9394
$this->_customer->expects($this->any())->method('getEmail')->willReturn(self::EMAIL_ADDRESS);
9495
$this->_helperView = $this->getMockBuilder(
9596
View::class
@@ -168,9 +169,8 @@ public function testGetSubscriptionObject()
168169
/**
169170
* @param bool $isSubscribed Is the subscriber subscribed?
170171
* @param bool $expectedValue The expected value - Whether the subscriber is subscribed or not.
171-
*
172-
* @dataProvider getIsSubscribedProvider
173-
*/
172+
* */
173+
#[DataProvider('getIsSubscribedProvider')]
174174
public function testGetIsSubscribed($isSubscribed, $expectedValue)
175175
{
176176
$this->_subscriber->expects($this->once())->method('isSubscribed')->willReturn($isSubscribed);
@@ -188,9 +188,8 @@ public static function getIsSubscribedProvider()
188188
/**
189189
* @param bool $isNewsletterEnabled Determines if the newsletter is enabled
190190
* @param bool $expectedValue The expected value - Whether the newsletter is enabled or not
191-
*
192-
* @dataProvider isNewsletterEnabledProvider
193-
*/
191+
* */
192+
#[DataProvider('isNewsletterEnabledProvider')]
194193
public function testIsNewsletterEnabled($isNewsletterEnabled, $expectedValue)
195194
{
196195
$this->_formRegister->expects($this->once())

app/code/Magento/Customer/Test/Unit/Block/Account/LinkTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1313
use Magento\Framework\View\Layout;
1414
use PHPUnit\Framework\TestCase;
15+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1516

1617
class LinkTest extends TestCase
1718
{
19+
use MockCreationTrait;
20+
1821
public function testGetHref()
1922
{
2023
$objectManager = new ObjectManager($this);
@@ -24,12 +27,10 @@ public function testGetHref()
2427
->onlyMethods(
2528
['getAccountUrl']
2629
)->getMock();
27-
$layout = $this->getMockBuilder(
28-
Layout::class
29-
)->disableOriginalConstructor()
30-
->addMethods(
31-
['helper']
32-
)->getMock();
30+
$layout = $this->createPartialMockWithReflection(
31+
Layout::class,
32+
['helper']
33+
);
3334

3435
$objectManager->prepareObjectManager();
3536
$block = $objectManager->getObject(

app/code/Magento/Customer/Test/Unit/Block/Account/NavigationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class NavigationTest extends TestCase
4444
protected function setUp(): void
4545
{
4646
$this->contextMock = $this->createMock(Context::class);
47-
$this->layoutMock = $this->getMockForAbstractClass(LayoutInterface::class);
47+
$this->layoutMock = $this->createMock(LayoutInterface::class);
4848
$this->contextMock->expects($this->any())
4949
->method('getLayout')
5050
->willReturn($this->layoutMock);

app/code/Magento/Customer/Test/Unit/Block/Account/RegisterLinkTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Math\Random;
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1616
use Magento\Framework\View\Helper\SecureHtmlRenderer;
17+
use PHPUnit\Framework\Attributes\DataProvider;
1718
use PHPUnit\Framework\TestCase;
1819

1920
/**
@@ -46,9 +47,9 @@ protected function setUp(): void
4647
* @param bool $isAuthenticated
4748
* @param bool $isRegistrationAllowed
4849
* @param bool $result
49-
* @dataProvider dataProviderToHtml
5050
* @return void
5151
*/
52+
#[DataProvider('dataProviderToHtml')]
5253
public function testToHtml($isAuthenticated, $isRegistrationAllowed, $result)
5354
{
5455
$context = $this->_objectManager->getObject(\Magento\Framework\View\Element\Template\Context::class);

app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
use Magento\Framework\View\Page\Title;
2525
use PHPUnit\Framework\MockObject\MockObject;
2626
use PHPUnit\Framework\TestCase;
27+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
2728

2829
/**
2930
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3031
*/
3132
class EditTest extends TestCase
3233
{
34+
use MockCreationTrait;
35+
3336
/**
3437
* @var ObjectManager
3538
*/
@@ -88,11 +91,11 @@ protected function setUp(): void
8891
$this->addressRepositoryMock = $this->getMockBuilder(AddressRepositoryInterface::class)
8992
->getMock();
9093

91-
$this->customerSessionMock = $this->getMockBuilder(Session::class)
92-
->disableOriginalConstructor()
93-
->onlyMethods(['getCustomerId'])
94-
->addMethods(['getAddressFormData'])
95-
->getMock();
94+
$this->customerSessionMock = $this->createPartialMockWithReflection(
95+
Session::class,
96+
['getAddressFormData', 'getCustomerId'
97+
]
98+
);
9699

97100
$this->pageConfigMock = $this->getMockBuilder(Config::class)
98101
->disableOriginalConstructor()

app/code/Magento/Customer/Test/Unit/Block/Address/GridTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
use Magento\Theme\Block\Html\Pager;
2424
use PHPUnit\Framework\MockObject\MockObject;
2525
use PHPUnit\Framework\TestCase;
26+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
2627

2728
/**
2829
* Unit tests for \Magento\Customer\Block\Address\Grid class
2930
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3031
*/
3132
class GridTest extends TestCase
3233
{
34+
use MockCreationTrait;
35+
3336
/**
3437
* @var ObjectManager
3538
*/
@@ -79,7 +82,7 @@ protected function setUp(): void
7982
->onlyMethods(['create'])
8083
->getMock();
8184

82-
$this->urlBuilder = $this->getMockForAbstractClass(UrlInterface::class);
85+
$this->urlBuilder = $this->createMock(UrlInterface::class);
8386

8487
$this->gridBlock = $this->objectManager->getObject(
8588
Grid::class,
@@ -99,14 +102,12 @@ public function testGetChildHtml()
99102
{
100103
$customerId = 1;
101104
$outputString = 'OutputString';
102-
/** @var BlockInterface|MockObject $block */
103-
$block = $this->getMockBuilder(BlockInterface::class)
104-
->addMethods(['setCollection'])
105-
->getMockForAbstractClass();
105+
/** @var Pager|MockObject $block */
106+
$block = $this->createPartialMock(Pager::class, ['setCollection']);
106107
/** @var LayoutInterface|MockObject $layout */
107-
$layout = $this->getMockForAbstractClass(LayoutInterface::class);
108+
$layout = $this->createMock(LayoutInterface::class);
108109
/** @var CustomerInterface|MockObject $customer */
109-
$customer = $this->getMockForAbstractClass(CustomerInterface::class);
110+
$customer = $this->createMock(CustomerInterface::class);
110111
/** @var MockObject */
111112
$addressCollection = $this->getMockBuilder(Collection::class)
112113
->disableOriginalConstructor()
@@ -151,13 +152,13 @@ public function testGetAdditionalAddresses()
151152
{
152153
$customerId = 1;
153154
/** @var CustomerInterface|MockObject $customer */
154-
$customer = $this->getMockForAbstractClass(CustomerInterface::class);
155+
$customer = $this->createMock(CustomerInterface::class);
155156
/** @var MockObject */
156157
$addressCollection = $this->getMockBuilder(Collection::class)
157158
->disableOriginalConstructor()
158159
->onlyMethods(['setOrder', 'setCustomerFilter', 'load', 'getIterator','addFieldToFilter'])
159160
->getMock();
160-
$addressDataModel = $this->getMockForAbstractClass(AddressInterface::class);
161+
$addressDataModel = $this->createMock(AddressInterface::class);
161162
$address = $this->getMockBuilder(Address::class)
162163
->disableOriginalConstructor()
163164
->onlyMethods(['getId', 'getDataModel'])
@@ -191,7 +192,7 @@ public function testGetStreetAddress()
191192
{
192193
$street = ['Line 1', 'Line 2'];
193194
$expectedAddress = 'Line 1, Line 2';
194-
$address = $this->getMockForAbstractClass(AddressInterface::class);
195+
$address = $this->createMock(AddressInterface::class);
195196
$address->expects($this->atLeastOnce())->method('getStreet')->willReturn($street);
196197
$this->assertEquals($expectedAddress, $this->gridBlock->getStreetAddress($address));
197198
}

0 commit comments

Comments
 (0)