Skip to content

Commit 1d7dea8

Browse files
fix unit tests
1 parent ad4138c commit 1d7dea8

File tree

4 files changed

+46
-29
lines changed

4 files changed

+46
-29
lines changed

app/code/Magento/AsynchronousOperations/Test/Unit/Model/AccessManagerTest.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,40 @@
1212
use Magento\Framework\AuthorizationInterface;
1313
use Magento\Framework\EntityManager\EntityManager;
1414
use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface;
15+
use PHPUnit\Framework\MockObject\MockObject;
16+
use PHPUnit\Framework\TestCase;
1517

16-
class AccessManagerTest extends \PHPUnit\Framework\TestCase
18+
class AccessManagerTest extends TestCase
1719
{
1820
/**
1921
* @var AccessManager
2022
*/
2123
private $model;
2224

2325
/**
24-
* @var \PHPUnit\Framework\MockObject\MockObject
26+
* @var MockObject
2527
*/
2628
private $userContextMock;
2729

2830
/**
29-
* @var \PHPUnit\Framework\MockObject\MockObject
31+
* @var MockObject
3032
*/
3133
private $entityManagerMock;
3234

3335
/**
34-
* @var \PHPUnit\Framework\MockObject\MockObject
36+
* @var MockObject
3537
*/
3638
private $bulkSummaryFactoryMock;
3739

3840
/**
39-
* @var \PHPUnit\Framework\MockObject\MockObject
41+
* @var MockObject
4042
*/
4143
private $authorizationMock;
4244

43-
protected function setUp()
45+
/**
46+
* @inheritDoc
47+
*/
48+
protected function setUp(): void
4449
{
4550
$this->userContextMock = $this->createMock(UserContextInterface::class);
4651
$this->entityManagerMock = $this->createMock(EntityManager::class);
@@ -60,31 +65,38 @@ protected function setUp()
6065

6166
/**
6267
* @dataProvider summaryDataProvider
63-
* @param string $bulkUserId
68+
* @param int $bulkUserId
6469
* @param bool $expectedResult
70+
* @return void
6571
*/
66-
public function testIsAllowedForBulkUuid($bulkUserId, $expectedResult)
72+
public function testIsAllowedForBulkUuid(int $bulkUserId, bool $expectedResult): void
6773
{
6874
$adminId = 1;
6975
$uuid = 'test-001';
7076
$bulkSummaryMock = $this->createMock(BulkSummaryInterface::class);
7177

72-
$this->bulkSummaryFactoryMock->expects($this->once())->method('create')->willReturn($bulkSummaryMock);
78+
$this->bulkSummaryFactoryMock->expects($this->once())
79+
->method('create')
80+
->willReturn($bulkSummaryMock);
7381
$this->entityManagerMock->expects($this->once())
7482
->method('load')
7583
->with($bulkSummaryMock, $uuid)
7684
->willReturn($bulkSummaryMock);
7785

78-
$bulkSummaryMock->expects($this->once())->method('getUserId')->willReturn($bulkUserId);
79-
$this->userContextMock->expects($this->once())->method('getUserId')->willReturn($adminId);
86+
$bulkSummaryMock->expects($this->once())
87+
->method('getUserId')
88+
->willReturn($bulkUserId);
89+
$this->userContextMock->expects($this->once())
90+
->method('getUserId')
91+
->willReturn($adminId);
8092

8193
$this->assertEquals($this->model->isAllowedForBulkUuid($uuid), $expectedResult);
8294
}
8395

8496
/**
8597
* @return array
8698
*/
87-
public static function summaryDataProvider()
99+
public static function summaryDataProvider(): array
88100
{
89101
return [
90102
[2, false],

app/code/Magento/AsynchronousOperations/Test/Unit/Model/ResourceModel/System/Message/Collection/Synchronized/PluginTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\AdminNotification\Model\System\Message;
1212
use Magento\AdminNotification\Model\System\MessageFactory;
1313
use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface;
14+
use Magento\AsynchronousOperations\Model\AccessManager;
1415
use Magento\AsynchronousOperations\Model\BulkNotificationManagement;
1516
use Magento\AsynchronousOperations\Model\BulkSummary;
1617
use Magento\AsynchronousOperations\Model\Operation\Details;
@@ -19,6 +20,7 @@
1920
use Magento\Authorization\Model\UserContextInterface;
2021
use Magento\Framework\AuthorizationInterface;
2122
use Magento\Framework\Bulk\BulkStatusInterface;
23+
use Magento\Framework\Encryption\Encryptor;
2224
use PHPUnit\Framework\MockObject\MockObject;
2325
use PHPUnit\Framework\TestCase;
2426

@@ -78,7 +80,12 @@ class PluginTest extends TestCase
7880
private $statusMapper;
7981

8082
/**
81-
* @var string
83+
* @var AccessManager|MockObject
84+
*/
85+
private $accessManager;
86+
87+
/**
88+
* @var Encryptor|MockObject
8289
*/
8390
private $encryptor;
8491

@@ -97,6 +104,8 @@ protected function setUp(): void
97104
$this->collectionMock = $this->createMock(Synchronized::class);
98105
$this->bulkNotificationMock = $this->createMock(BulkNotificationManagement::class);
99106
$this->statusMapper = $this->createMock(StatusMapper::class);
107+
$this->accessManager = $this->createMock(AccessManager::class);
108+
$this->encryptor = $this->createMock(Encryptor::class);
100109
$this->plugin = new Plugin(
101110
$this->messagefactoryMock,
102111
$this->bulkStatusMock,
@@ -114,8 +123,7 @@ public function testAfterToArrayIfNotAllowed()
114123
$result = [];
115124
$this->accessManager
116125
->expects($this->once())
117-
->method('isAllowed')
118-
->with($this->resourceName)
126+
->method('isOwnActionsAllowed')
119127
->willReturn(false);
120128
$this->assertEquals($result, $this->plugin->afterToArray($this->collectionMock, $result));
121129
}

app/code/Magento/AsynchronousOperations/Test/Unit/Ui/Component/AdminNotification/PluginTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\AdminNotification\Ui\Component\DataProvider\DataProvider;
1111
use Magento\AsynchronousOperations\Ui\Component\AdminNotification\Plugin;
12-
use Magento\Framework\AuthorizationInterface;
1312
use Magento\AsynchronousOperations\Model\AccessManager;
1413
use PHPUnit\Framework\MockObject\MockObject;
1514
use PHPUnit\Framework\TestCase;
@@ -22,16 +21,14 @@ class PluginTest extends TestCase
2221
private $plugin;
2322

2423
/**
25-
* @var MockObject
24+
* @var AccessManager|MockObject
2625
*/
27-
private $authorizationMock;
26+
private $accessMangerMock;
2827

2928
protected function setUp(): void
3029
{
31-
$this->authorizationMock = $this->getMockForAbstractClass(AuthorizationInterface::class);
32-
$this->plugin = new Plugin(
33-
$this->authorizationMock
34-
);
30+
$this->accessMangerMock = $this->createMock(AccessManager::class);
31+
$this->plugin = new Plugin($this->accessMangerMock);
3532
}
3633

3734
public function testAfterGetMeta()
@@ -49,7 +46,10 @@ public function testAfterGetMeta()
4946
]
5047
];
5148
$dataProviderMock = $this->createMock(DataProvider::class);
52-
$this->authorizationMock->expects($this->once())->method('isAllowed')->willReturn(true);
49+
$this->accessMangerMock->expects($this->once())
50+
->method('isOwnActionsAllowed')
51+
->willReturn(true);
52+
5353
$this->assertEquals($expectedResult, $this->plugin->afterGetMeta($dataProviderMock, $result));
5454
}
5555
}

app/code/Magento/AsynchronousOperations/Ui/Component/AdminNotification/Plugin.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class Plugin
2525
private $isAllowed;
2626

2727
/**
28-
* Plugin constructor.
29-
*
3028
* @param AccessManager $accessManager
3129
*/
3230
public function __construct(
@@ -43,14 +41,13 @@ public function __construct(
4341
* @return array
4442
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4543
*/
46-
public function afterGetMeta(
47-
DataProvider $dataProvider,
48-
$result
49-
) {
44+
public function afterGetMeta(DataProvider $dataProvider, $result)
45+
{
5046
if (!isset($this->isAllowed)) {
5147
$this->isAllowed = $this->accessManager->isOwnActionsAllowed();
5248
}
5349
$result['columns']['arguments']['data']['config']['isAllowed'] = $this->isAllowed;
50+
5451
return $result;
5552
}
5653
}

0 commit comments

Comments
 (0)