Skip to content

Commit aceb8f7

Browse files
Merge remote-tracking branch 'origin/Arrows-AC-15503' into Arrows-AC-14808-v4
2 parents a7bf9f7 + 14c459d commit aceb8f7

File tree

98 files changed

+1718
-1742
lines changed

Some content is hidden

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

98 files changed

+1718
-1742
lines changed

app/code/Magento/Integration/Test/Unit/Block/Adminhtml/Integration/Edit/Tab/InfoTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
namespace Magento\Integration\Test\Unit\Block\Adminhtml\Integration\Edit\Tab;
99

10+
use Magento\Framework\App\ObjectManager as AppObjectManager;
11+
use Magento\Framework\Json\Helper\Data as JsonHelper;
12+
use Magento\Framework\ObjectManagerInterface;
1013
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1114
use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info;
15+
use PHPUnit\Framework\MockObject\MockObject;
1216
use PHPUnit\Framework\TestCase;
1317

1418
/**
@@ -22,32 +26,49 @@ class InfoTest extends TestCase
2226
private $objectManager;
2327

2428
/**
25-
* @var \Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info
29+
* @var Info
2630
*/
2731
private $infoBlock;
2832

33+
/**
34+
* @var ObjectManagerInterface|MockObject
35+
*/
36+
private $objectManagerMock;
37+
2938
protected function setUp(): void
3039
{
3140
$this->objectManager = new ObjectManager($this);
3241

42+
// Mock JsonHelper for ObjectManager
43+
$jsonHelperMock = $this->getMockBuilder(JsonHelper::class)
44+
->disableOriginalConstructor()
45+
->getMock();
46+
47+
// Mock ObjectManager to avoid "ObjectManager isn't initialized" error
48+
$this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
49+
$this->objectManagerMock->method('get')
50+
->willReturn($jsonHelperMock);
51+
52+
AppObjectManager::setInstance($this->objectManagerMock);
53+
3354
$this->infoBlock = $this->objectManager->getObject(
3455
Info::class
3556
);
3657
}
3758

38-
public function testGetTabLabelAndTitle()
59+
public function testGetTabLabelAndTitle(): void
3960
{
4061
$tabString = 'Integration Info';
4162
$this->assertEquals($tabString, $this->infoBlock->getTabLabel());
4263
$this->assertEquals($tabString, $this->infoBlock->getTabTitle());
4364
}
4465

45-
public function testCanShowTab()
66+
public function testCanShowTab(): void
4667
{
4768
$this->assertTrue($this->infoBlock->canShowTab());
4869
}
4970

50-
public function testIsHidden()
71+
public function testIsHidden(): void
5172
{
5273
$this->assertFalse($this->infoBlock->isHidden());
5374
}

app/code/Magento/Integration/Test/Unit/Block/Adminhtml/Integration/Edit/Tab/WebapiTest.php

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

1010
use Magento\Framework\Acl\AclResource\ProviderInterface;
1111
use Magento\Framework\Acl\RootResource;
12+
use Magento\Framework\App\ObjectManager as AppObjectManager;
13+
use Magento\Framework\Json\Helper\Data as JsonHelper;
14+
use Magento\Framework\ObjectManagerInterface;
1215
use Magento\Framework\Registry;
1316
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1417
use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info;
@@ -17,8 +20,13 @@
1720
use Magento\Integration\Helper\Data;
1821
use Magento\Integration\Model\Integration as IntegrationModel;
1922
use Magento\Integration\Model\IntegrationService;
23+
use PHPUnit\Framework\Attributes\DataProvider;
2024
use PHPUnit\Framework\TestCase;
2125

26+
/**
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28+
*/
29+
2230
class WebapiTest extends TestCase
2331
{
2432
/**
@@ -27,7 +35,7 @@ class WebapiTest extends TestCase
2735
private $objectManager;
2836

2937
/**
30-
* @var Info
38+
* @var Webapi
3139
*/
3240
private $webapiBlock;
3341

@@ -60,6 +68,19 @@ protected function setUp(): void
6068
{
6169
$this->objectManager = new ObjectManager($this);
6270

71+
// Mock JsonHelper that Backend blocks need
72+
$jsonHelperMock = $this->getMockBuilder(JsonHelper::class)
73+
->disableOriginalConstructor()
74+
->getMock();
75+
76+
// Mock ObjectManager to return mocked dependencies
77+
$objectManagerMock = $this->createMock(ObjectManagerInterface::class);
78+
$objectManagerMock->method('get')
79+
->willReturn($jsonHelperMock);
80+
81+
// Set global ObjectManager instance for Backend blocks
82+
AppObjectManager::setInstance($objectManagerMock);
83+
6384
$this->registry = $this->getMockBuilder(Registry::class)
6485
->disableOriginalConstructor()
6586
->getMock();
@@ -68,9 +89,7 @@ protected function setUp(): void
6889
->disableOriginalConstructor()
6990
->getMock();
7091

71-
$this->aclResourceProvider = $this->getMockBuilder(ProviderInterface::class)
72-
->disableOriginalConstructor()
73-
->getMockForAbstractClass();
92+
$this->aclResourceProvider = $this->createMock(ProviderInterface::class);
7493

7594
$this->integrationHelper = $this->getMockBuilder(Data::class)
7695
->disableOriginalConstructor()
@@ -82,20 +101,20 @@ protected function setUp(): void
82101
}
83102

84103
/**
85-
* @param array $integrationData
104+
* @param array<string, mixed>|null $integrationData
86105
* @param bool $expectedValue
87-
* @dataProvider canShowTabProvider
88106
*/
89-
public function testCanShowTab($integrationData, $expectedValue)
107+
#[DataProvider('canShowTabProvider')]
108+
public function testCanShowTab(?array $integrationData, bool $expectedValue): void
90109
{
91110
$this->webapiBlock = $this->getWebapiBlock($integrationData);
92111
$this->assertEquals($expectedValue, $this->webapiBlock->canShowTab());
93112
}
94113

95114
/**
96-
* @return array
115+
* @return array<string, array<string, mixed>>
97116
*/
98-
public static function canShowTabProvider()
117+
public static function canShowTabProvider(): array
99118
{
100119
return [
101120
'null data' => [
@@ -117,21 +136,25 @@ public static function canShowTabProvider()
117136
];
118137
}
119138

120-
public function testIsHidden()
139+
public function testIsHidden(): void
121140
{
122141
$this->webapiBlock = $this->getWebapiBlock();
123142
$this->assertFalse($this->webapiBlock->isHidden());
124143
}
125144

126145
/**
127-
* @param string $rootResourceId
128-
* @param array $integrationData
129-
* @param array $selectedResources
146+
* @param int|string $rootResourceId
147+
* @param array<string, mixed> $integrationData
148+
* @param array<int> $selectedResources
130149
* @param bool $expectedValue
131-
* @dataProvider isEverythingAllowedProvider
132150
*/
133-
public function testIsEverythingAllowed($rootResourceId, $integrationData, $selectedResources, $expectedValue)
134-
{
151+
#[DataProvider('isEverythingAllowedProvider')]
152+
public function testIsEverythingAllowed(
153+
int|string $rootResourceId,
154+
array $integrationData,
155+
array $selectedResources,
156+
bool $expectedValue
157+
): void {
135158
$this->webapiBlock = $this->getWebapiBlock($integrationData, $selectedResources);
136159
$this->rootResource->expects($this->once())
137160
->method('getId')
@@ -140,9 +163,9 @@ public function testIsEverythingAllowed($rootResourceId, $integrationData, $sele
140163
}
141164

142165
/**
143-
* @return array
166+
* @return array<string, array{string|int, array<string, mixed>, array<int>, bool}>
144167
*/
145-
public static function isEverythingAllowedProvider()
168+
public static function isEverythingAllowedProvider(): array
146169
{
147170
return [
148171
'root resource in array' => [
@@ -166,7 +189,7 @@ public static function isEverythingAllowedProvider()
166189
];
167190
}
168191

169-
public function testGetTree()
192+
public function testGetTree(): void
170193
{
171194
$this->webapiBlock = $this->getWebapiBlock();
172195
$resources = [
@@ -185,13 +208,16 @@ public function testGetTree()
185208
}
186209

187210
/**
188-
* @param string $rootResourceId
189-
* @param array $savedData
211+
* @param int|string $rootResourceId
212+
* @param array<string, mixed> $savedData
190213
* @param bool $expectedValue
191-
* @dataProvider isEverythingAllowedWithSavedFromDataProvider
192214
*/
193-
public function testIsEverythingAllowedWithSavedFromData($rootResourceId, $savedData, $expectedValue)
194-
{
215+
#[DataProvider('isEverythingAllowedWithSavedFromDataProvider')]
216+
public function testIsEverythingAllowedWithSavedFromData(
217+
int|string $rootResourceId,
218+
array $savedData,
219+
bool $expectedValue
220+
): void {
195221
$this->registry->expects($this->once())
196222
->method('registry')->with(IntegrationController::REGISTRY_KEY_CURRENT_RESOURCE)
197223
->willReturn($savedData);
@@ -206,9 +232,9 @@ public function testIsEverythingAllowedWithSavedFromData($rootResourceId, $saved
206232
}
207233

208234
/**
209-
* @return array
235+
* @return array<string, array{string|int, array<string, mixed>, bool}>
210236
*/
211-
public static function isEverythingAllowedWithSavedFromDataProvider()
237+
public static function isEverythingAllowedWithSavedFromDataProvider(): array
212238
{
213239
return [
214240
'root resource in array' => [
@@ -225,11 +251,11 @@ public static function isEverythingAllowedWithSavedFromDataProvider()
225251
}
226252

227253
/**
228-
* @param array $integrationData
229-
* @param array $selectedResources
230-
* @return Webapi|object
254+
* @param array<string, mixed>|null $integrationData
255+
* @param array<int> $selectedResources
256+
* @return Webapi
231257
*/
232-
private function getWebapiBlock($integrationData = [], array $selectedResources = [])
258+
private function getWebapiBlock(?array $integrationData = [], array $selectedResources = []): Webapi
233259
{
234260
if ($integrationData) {
235261
if (isset($integrationData['integration_id'])) {

app/code/Magento/Integration/Test/Unit/Block/Adminhtml/Widget/Grid/Column/Renderer/ButtonTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Backend\Block\Widget\Grid\Column;
1212
use Magento\Framework\DataObject;
1313
use Magento\Framework\Escaper;
14+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1415
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1516
use Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Button;
1617
use PHPUnit\Framework\MockObject\MockObject;
@@ -20,6 +21,7 @@
2021

2122
class ButtonTest extends TestCase
2223
{
24+
use MockCreationTrait;
2325
/**
2426
* @var Context|MockObject
2527
*/
@@ -81,13 +83,12 @@ function (string $style, string $selector): string {
8183
/**
8284
* Test the basic render action.
8385
*/
84-
public function testRender()
86+
public function testRender(): void
8587
{
86-
$column = $this->getMockBuilder(Column::class)
87-
->disableOriginalConstructor()
88-
->onlyMethods(['getId'])
89-
->addMethods(['getType', 'getIndex', 'getStyle', 'getOnclick'])
90-
->getMock();
88+
$column = $this->createPartialMockWithReflection(
89+
Column::class,
90+
['getId', 'getType', 'getIndex', 'getStyle', 'getOnclick']
91+
);
9192
$column->expects($this->any())
9293
->method('getType')
9394
->willReturn('bigButton');

app/code/Magento/Integration/Test/Unit/Block/Adminhtml/Widget/Grid/Column/Renderer/LinkTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Backend\Block\Widget\Grid\Column;
1212
use Magento\Framework\DataObject;
1313
use Magento\Framework\Escaper;
14+
use Magento\Framework\TestFramework\Unit\Helper\MockCreationTrait;
1415
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1516
use Magento\Framework\UrlInterface;
1617
use Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Link;
@@ -19,6 +20,7 @@
1920

2021
class LinkTest extends TestCase
2122
{
23+
use MockCreationTrait;
2224
/**
2325
* @var Context|MockObject
2426
*/
@@ -51,7 +53,7 @@ protected function setUp(): void
5153
{
5254
$this->escaperMock = $this->createMock(Escaper::class);
5355
$this->escaperMock->expects($this->any())->method('escapeHtml')->willReturnArgument(0);
54-
$this->urlBuilderMock = $this->getMockForAbstractClass(UrlInterface::class);
56+
$this->urlBuilderMock = $this->createMock(UrlInterface::class);
5557
$this->urlBuilderMock->expects($this->once())->method('getUrl')->willReturn('http://magento.loc/linkurl');
5658
$this->contextMock = $this->createPartialMock(
5759
Context::class,
@@ -77,10 +79,10 @@ protected function setUp(): void
7779
public function testRender(): void
7880
{
7981
$expectedResult = '<a href="http://magento.loc/linkurl" title="Link Caption">Link Caption</a>';
80-
$column = $this->getMockBuilder(Column::class)->disableOriginalConstructor()
81-
->onlyMethods(['getId'])
82-
->addMethods(['getCaption'])
83-
->getMock();
82+
$column = $this->createPartialMockWithReflection(
83+
Column::class,
84+
['getId', 'getCaption']
85+
);
8486
$column->expects($this->any())
8587
->method('getCaption')
8688
->willReturn('Link Caption');

0 commit comments

Comments
 (0)