Skip to content

Commit 88953ac

Browse files
authored
#23972 fix disabled guest checkout issue
Fix unit tests
1 parent 63ad4a3 commit 88953ac

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

app/code/Magento/Downloadable/Test/Unit/Observer/IsAllowedGuestCheckoutObserverTest.php

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Quote\Model\Quote;
1919
use Magento\Quote\Model\Quote\Item as QuoteItem;
2020
use Magento\Store\Model\ScopeInterface;
21+
use Magento\Store\Model\StoreManagerInterface;
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use PHPUnit\Framework\TestCase;
2324

@@ -27,7 +28,9 @@
2728
class IsAllowedGuestCheckoutObserverTest extends TestCase
2829
{
2930
private const XML_PATH_DISABLE_GUEST_CHECKOUT = 'catalog/downloadable/disable_guest_checkout';
30-
31+
32+
private const STUB_STORE_ID = 1;
33+
3134
/** @var IsAllowedGuestCheckoutObserver */
3235
private $isAllowedGuestCheckoutObserver;
3336

@@ -56,6 +59,11 @@ class IsAllowedGuestCheckoutObserverTest extends TestCase
5659
*/
5760
private $storeMock;
5861

62+
/**
63+
* @var MockObject|StoreManagerInterface
64+
*/
65+
private $storeManagerMock;
66+
5967
/**
6068
* Sets up the fixture, for example, open a network connection.
6169
* This method is called before a test is executed.
@@ -86,12 +94,20 @@ protected function setUp(): void
8694
->disableOriginalConstructor()
8795
->getMock();
8896

89-
$this->isAllowedGuestCheckoutObserver = (new ObjectManagerHelper($this))->getObject(
90-
IsAllowedGuestCheckoutObserver::class,
91-
[
92-
'scopeConfig' => $this->scopeConfigMock,
93-
]
94-
);
97+
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
98+
$this->storeManagerMock
99+
->method('getStore')
100+
->with(self::STUB_STORE_ID)
101+
->willReturn($this->storeMock);
102+
103+
$this->isAllowedGuestCheckoutObserver = (new ObjectManagerHelper($this))
104+
->getObject(
105+
IsAllowedGuestCheckoutObserver::class,
106+
[
107+
'scopeConfig' => $this->scopeConfigMock,
108+
'storeManager'=> $this->storeManagerMock
109+
]
110+
);
95111
}
96112

97113
/**
@@ -103,8 +119,6 @@ protected function setUp(): void
103119
*/
104120
public function testIsAllowedGuestCheckoutConfigSetToTrue($productType, $isAllowed): void
105121
{
106-
$storeId = 1;
107-
108122
if ($isAllowed) {
109123
$this->resultMock->expects($this->at(0))
110124
->method('setIsAllowed')
@@ -144,7 +158,7 @@ public function testIsAllowedGuestCheckoutConfigSetToTrue($productType, $isAllow
144158

145159
$this->storeMock->expects($this->any())
146160
->method('getId')
147-
->willReturn($storeId);
161+
->willReturn(self::STUB_STORE_ID);
148162

149163
$this->eventMock->expects($this->once())
150164
->method('getResult')
@@ -159,7 +173,7 @@ public function testIsAllowedGuestCheckoutConfigSetToTrue($productType, $isAllow
159173
->with(
160174
self::XML_PATH_DISABLE_GUEST_CHECKOUT,
161175
ScopeInterface::SCOPE_STORE,
162-
$storeId
176+
self::STUB_STORE_ID
163177
)
164178
->willReturn(true);
165179

@@ -186,8 +200,6 @@ public function dataProviderForTestisAllowedGuestCheckoutConfigSetToTrue(): arra
186200

187201
public function testIsAllowedGuestCheckoutConfigSetToFalse(): void
188202
{
189-
$storeId = 1;
190-
191203
$product = $this->getMockBuilder(Product::class)
192204
->disableOriginalConstructor()
193205
->setMethods(['getTypeId'])
@@ -218,10 +230,10 @@ public function testIsAllowedGuestCheckoutConfigSetToFalse(): void
218230
$this->eventMock->expects($this->once())
219231
->method('getStore')
220232
->willReturn($this->storeMock);
221-
233+
222234
$this->storeMock->expects($this->any())
223235
->method('getId')
224-
->willReturn($storeId);
236+
->willReturn(self::STUB_STORE_ID);
225237

226238
$this->eventMock->expects($this->once())
227239
->method('getResult')
@@ -236,7 +248,7 @@ public function testIsAllowedGuestCheckoutConfigSetToFalse(): void
236248
->with(
237249
self::XML_PATH_DISABLE_GUEST_CHECKOUT,
238250
ScopeInterface::SCOPE_STORE,
239-
$storeId
251+
self::STUB_STORE_ID
240252
)
241253
->willReturn(false);
242254

0 commit comments

Comments
 (0)