Skip to content

Commit b6aa0d7

Browse files
committed
ACP2E-2850: added unit test
1 parent 4036a7a commit b6aa0d7

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\CheckoutAgreements\Test\Unit\Model;
20+
21+
use Magento\CheckoutAgreements\Model\EmulateStore;
22+
use Magento\Framework\Exception\NoSuchEntityException;
23+
use Magento\Store\Api\Data\StoreInterface;
24+
use Magento\Store\Model\StoreManager;
25+
use PHPUnit\Framework\MockObject\MockObject;
26+
use PHPUnit\Framework\TestCase;
27+
28+
class EmulateStoreTest extends TestCase
29+
{
30+
/**
31+
* @var EmulateStore
32+
*/
33+
private EmulateStore $emulateStore;
34+
35+
/**
36+
* @var StoreManager|MockObject
37+
*/
38+
private StoreManager|MockObject $storeManager;
39+
40+
/**
41+
* @var StoreInterface|MockObject
42+
*/
43+
private StoreInterface|MockObject $store;
44+
45+
public function setUp(): void
46+
{
47+
$this->storeManager = $this->createMock(StoreManager::class);
48+
$this->store = $this->getMockForAbstractClass(StoreInterface::class);
49+
$this->emulateStore = new EmulateStore(
50+
$this->storeManager
51+
);
52+
}
53+
54+
/**
55+
* @param int $storeId
56+
* @param int $currentStoreId
57+
* @return void
58+
* @throws NoSuchEntityException
59+
* @dataProvider executeDataProvider
60+
*/
61+
public function testExecute(int $storeId, int $currentStoreId): void
62+
{
63+
$this->store->expects($this->once())
64+
->method('getId')
65+
->willReturn($currentStoreId);
66+
$this->storeManager->expects($this->once())
67+
->method('getStore')
68+
->willReturn($this->store);
69+
70+
if ($storeId !== $currentStoreId) {
71+
$expected = [
72+
[$storeId],
73+
[$currentStoreId]
74+
];
75+
$this->storeManager->expects($this->exactly(2))
76+
->method('setCurrentStore')
77+
->willReturnCallback(function (...$args) use (&$expected) {
78+
$expectedArgs = array_shift($expected);
79+
$this->assertSame($expectedArgs, $args);
80+
});
81+
}
82+
83+
$this->emulateStore->execute($storeId, function () use ($currentStoreId) {
84+
}, [1, 2, 3]);
85+
}
86+
87+
/**
88+
* @return array[]
89+
*/
90+
public function executeDataProvider(): array
91+
{
92+
return [
93+
'no-emulation' => ['storeId' => 1, 'currentStoreId' => 1],
94+
'emulation' => ['storeId' => 2, 'currentStoreId' => 1]
95+
];
96+
}
97+
}

0 commit comments

Comments
 (0)