Skip to content

Commit 341dd1f

Browse files
ShradddhaShradddha
authored andcommitted
AC-10621::PHPUnit 10 upgrade error: ‘RuntimeException: ObjectManager isn't initialized’
1 parent 57c848a commit 341dd1f

File tree

7 files changed

+95
-0
lines changed

7 files changed

+95
-0
lines changed

app/code/Magento/AdminNotification/Test/Unit/Block/ToolbarEntryTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
use Magento\AdminNotification\Block\ToolbarEntry;
1414
use Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread;
15+
use Magento\Directory\Helper\Data as DirectoryHelper;
16+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1517
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1618
use PHPUnit\Framework\TestCase;
1719

@@ -26,6 +28,17 @@ class ToolbarEntryTest extends TestCase
2628
protected function _getBlockInstance($unreadNotifications)
2729
{
2830
$objectManagerHelper = new ObjectManager($this);
31+
$objects = [
32+
[
33+
JsonHelper::class,
34+
$this->createMock(JsonHelper::class)
35+
],
36+
[
37+
DirectoryHelper::class,
38+
$this->createMock(DirectoryHelper::class)
39+
]
40+
];
41+
$objectManagerHelper->prepareObjectManager($objects);
2942
// mock collection of unread notifications
3043
$notificationList = $this->createPartialMock(
3144
Unread::class,
@@ -52,6 +65,18 @@ public function testGetLatestUnreadNotifications()
5265
{
5366
$helper = new ObjectManager($this);
5467

68+
$objects = [
69+
[
70+
JsonHelper::class,
71+
$this->createMock(JsonHelper::class)
72+
],
73+
[
74+
DirectoryHelper::class,
75+
$this->createMock(DirectoryHelper::class)
76+
]
77+
];
78+
$helper->prepareObjectManager($objects);
79+
5580
// 1. Create mocks
5681
$notificationList = $this->createMock(Unread::class);
5782

app/code/Magento/Backend/Test/Unit/App/Response/Http/FileFactoryTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
18+
use Magento\Framework\App\Response\FileFactory;
1819

1920
class FileFactoryTest extends TestCase
2021
{
@@ -46,6 +47,14 @@ class FileFactoryTest extends TestCase
4647
protected function setUp(): void
4748
{
4849
$helper = new ObjectManager($this);
50+
$objects = [
51+
[
52+
FileFactory::class,
53+
$this->createMock(FileFactory::class)
54+
]
55+
];
56+
$helper->prepareObjectManager($objects);
57+
4958
$this->_responseMock = $this->createPartialMock(
5059
Http::class,
5160
['setRedirect', '__wakeup']

app/code/Magento/Backend/Test/Unit/Block/MenuTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Magento\Backend\Model\Menu\Filter\IteratorFactory;
1717
use Magento\Backend\Model\Menu\Item;
1818
use Magento\Backend\Model\UrlInterface;
19+
use Magento\Directory\Helper\Data as DirectoryHelper;
20+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1921
use Magento\Framework\Locale\ResolverInterface;
2022
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2123
use PHPUnit\Framework\MockObject\MockObject;
@@ -73,6 +75,17 @@ protected function setUp(): void
7375
->getMock();
7476

7577
$objectManagerHelper = new ObjectManagerHelper($this);
78+
$objects = [
79+
[
80+
JsonHelper::class,
81+
$this->createMock(JsonHelper::class)
82+
],
83+
[
84+
DirectoryHelper::class,
85+
$this->createMock(DirectoryHelper::class)
86+
]
87+
];
88+
$objectManagerHelper->prepareObjectManager($objects);
7689
$this->menu = $objectManagerHelper->getObject(
7790
Menu::class,
7891
[

app/code/Magento/Backend/Test/Unit/Block/Page/System/Config/Robots/ResetTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Backend\Block\Template\Context;
1515
use Magento\Framework\App\Config\ScopeConfigInterface;
1616
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
17+
use Magento\Framework\View\Helper\SecureHtmlRenderer;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
1920

@@ -37,6 +38,13 @@ protected function setUp(): void
3738
$this->configMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
3839

3940
$objectHelper = new ObjectManager($this);
41+
$objects = [
42+
[
43+
SecureHtmlRenderer::class,
44+
$this->createMock(SecureHtmlRenderer::class)
45+
]
46+
];
47+
$objectHelper->prepareObjectManager($objects);
4048
$context = $objectHelper->getObject(
4149
Context::class,
4250
['scopeConfig' => $this->configMock]

app/code/Magento/Backend/Test/Unit/Block/Widget/Button/SplitTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace Magento\Backend\Test\Unit\Block\Widget\Button;
99

1010
use Magento\Backend\Block\Widget\Button\SplitButton;
11+
use Magento\Directory\Helper\Data as DirectoryHelper;
12+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1113
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1214
use PHPUnit\Framework\TestCase;
1315

@@ -16,6 +18,17 @@ class SplitTest extends TestCase
1618
public function testHasSplit()
1719
{
1820
$objectManagerHelper = new ObjectManager($this);
21+
$objects = [
22+
[
23+
JsonHelper::class,
24+
$this->createMock(JsonHelper::class)
25+
],
26+
[
27+
DirectoryHelper::class,
28+
$this->createMock(DirectoryHelper::class)
29+
]
30+
];
31+
$objectManagerHelper->prepareObjectManager($objects);
1932
/** @var SplitButton $block */
2033
$block = $objectManagerHelper->getObject(SplitButton::class);
2134
$this->assertTrue($block->hasSplit());

app/code/Magento/Backend/Test/Unit/Block/Widget/ButtonTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
use Magento\Backend\Block\Widget\Button;
1414
use Magento\Backend\Model\Url;
15+
use Magento\Directory\Helper\Data as DirectoryHelper;
16+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1517
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1618
use Magento\Framework\View\Layout;
1719
use PHPUnit\Framework\MockObject\MockObject;
@@ -49,6 +51,18 @@ protected function setUp(): void
4951
];
5052

5153
$objectManagerHelper = new ObjectManager($this);
54+
$objects = [
55+
[
56+
JsonHelper::class,
57+
$this->createMock(JsonHelper::class)
58+
],
59+
[
60+
DirectoryHelper::class,
61+
$this->createMock(DirectoryHelper::class)
62+
]
63+
];
64+
$objectManagerHelper->prepareObjectManager($objects);
65+
5266
$this->_blockMock = $objectManagerHelper->getObject(Button::class, $arguments);
5367
}
5468

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ExtendedTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
use Magento\Backend\Block\Widget\Grid\ColumnSet;
1414
use Magento\Backend\Block\Widget\Grid\Extended;
15+
use Magento\Directory\Helper\Data as DirectoryHelper;
1516
use Magento\Framework\App\Request\Http;
1617
use Magento\Framework\Data\Collection;
18+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1719
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1820
use Magento\Framework\View\Layout;
1921
use PHPUnit\Framework\TestCase;
@@ -28,6 +30,17 @@ class ExtendedTest extends TestCase
2830
protected function setUp(): void
2931
{
3032
$this->_objectManager = new ObjectManager($this);
33+
$objects = [
34+
[
35+
JsonHelper::class,
36+
$this->createMock(JsonHelper::class)
37+
],
38+
[
39+
DirectoryHelper::class,
40+
$this->createMock(DirectoryHelper::class)
41+
]
42+
];
43+
$this->_objectManager->prepareObjectManager($objects);
3144
}
3245

3346
public function testPrepareLoadedCollection()

0 commit comments

Comments
 (0)