Skip to content

Commit 57c848a

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

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
use Magento\Backend\Block\Widget\Grid\Massaction;
1515
use Magento\Backend\Block\Widget\Grid\Massaction\Extended;
1616
use Magento\Backend\Model\Url;
17+
use Magento\Directory\Helper\Data as DirectoryHelper;
1718
use Magento\Framework\App\Request\Http;
1819
use Magento\Framework\Data\Collection;
20+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1921
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2022
use Magento\Framework\View\Layout;
2123
use PHPUnit\Framework\MockObject\MockObject;
@@ -98,6 +100,18 @@ protected function setUp(): void
98100
];
99101

100102
$objectManagerHelper = new ObjectManager($this);
103+
$objects = [
104+
[
105+
JsonHelper::class,
106+
$this->createMock(JsonHelper::class)
107+
],
108+
[
109+
DirectoryHelper::class,
110+
$this->createMock(DirectoryHelper::class)
111+
]
112+
];
113+
$objectManagerHelper->prepareObjectManager($objects);
114+
101115
$this->_block = $objectManagerHelper->getObject(
102116
Extended::class,
103117
$arguments

app/code/Magento/Backend/Test/Unit/Model/Auth/SessionTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Backend\Model\Auth\Session;
1212
use Magento\Framework\Acl;
1313
use Magento\Framework\Acl\Builder;
14+
use Magento\Framework\Session\SessionStartChecker;
1415
use Magento\Framework\Session\Storage;
1516
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1617
use Magento\Framework\Stdlib\Cookie\PhpCookieManager;
@@ -96,6 +97,13 @@ protected function setUp(): void
9697
->disableOriginalConstructor()
9798
->getMock();
9899
$objectManager = new ObjectManager($this);
100+
$objects = [
101+
[
102+
SessionStartChecker::class,
103+
$this->createMock(SessionStartChecker::class)
104+
]
105+
];
106+
$objectManager->prepareObjectManager($objects);
99107
$this->session = $objectManager->getObject(
100108
Session::class,
101109
[
@@ -127,7 +135,8 @@ public function testRefreshAcl($isUserPassedViaParams)
127135
->getMock();
128136
$this->aclBuilder->expects($this->any())->method('getAcl')->willReturn($aclMock);
129137
$userMock = $this->getMockBuilder(User::class)
130-
->setMethods(['getReloadAclFlag', 'setReloadAclFlag', 'unsetData', 'save'])
138+
->addMethods(['getReloadAclFlag','setReloadAclFlag'])
139+
->onlyMethods(['unsetData', 'save'])
131140
->disableOriginalConstructor()
132141
->getMock();
133142
$userMock->expects($this->any())->method('getReloadAclFlag')->willReturn(true);

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/EditTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class EditTest extends TestCase
117117
*/
118118
protected function setUp(): void
119119
{
120-
$objectManager = new ObjectManager($this);
120+
$this->objectManager = new ObjectManager($this);
121121

122122
$objects = [
123123
[
@@ -141,7 +141,7 @@ protected function setUp(): void
141141
$this->createMock(Session::class)
142142
]
143143
];
144-
$objectManager->prepareObjectManager($objects);
144+
$this->objectManager->prepareObjectManager($objects);
145145

146146
$this->categoryMock = $this->createPartialMock(
147147
Category::class,
@@ -241,7 +241,7 @@ protected function setUp(): void
241241
->method('getResultRedirectFactory')
242242
->willReturn($this->resultRedirectFactoryMock);
243243

244-
$this->edit = $objectManager->getObject(
244+
$this->edit = $this->objectManager->getObject(
245245
Edit::class,
246246
[
247247
'context' => $this->contextMock,

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/SaveTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class SaveTest extends TestCase
8989
*/
9090
protected function setUp(): void
9191
{
92-
$objectManager = new ObjectManager($this);
92+
$this->objectManager = new ObjectManager($this);
9393

9494
$objects = [
9595
[
@@ -109,7 +109,7 @@ protected function setUp(): void
109109
$this->createMock(Session::class)
110110
]
111111
];
112-
$objectManager->prepareObjectManager($objects);
112+
$this->objectManager->prepareObjectManager($objects);
113113

114114
$this->resultRedirectFactoryMock = $this->createPartialMock(
115115
RedirectFactory::class,
@@ -151,7 +151,7 @@ protected function setUp(): void
151151
['addSuccessMessage', 'getMessages']
152152
);
153153

154-
$this->save = $objectManager->getObject(
154+
$this->save = $this->objectManager->getObject(
155155
Save::class,
156156
[
157157
'request' => $this->requestMock,

app/code/Magento/Cms/Test/Unit/Block/Widget/Page/LinkTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LinkTest extends TestCase
4545

4646
protected function setUp(): void
4747
{
48-
$objectManager = new ObjectManager($this);
48+
$this->objectManager = new ObjectManager($this);
4949
$objects = [
5050
[
5151
SecureHtmlRenderer::class,
@@ -56,12 +56,12 @@ protected function setUp(): void
5656
$this->createMock(Random::class)
5757
]
5858
];
59-
$objectManager->prepareObjectManager($objects);
59+
$this->objectManager->prepareObjectManager($objects);
6060

6161
$this->mockCmsPage = $this->createMock(Page::class);
6262
$this->mockResourcePage = $this->createMock(\Magento\Cms\Model\ResourceModel\Page::class);
6363

64-
$this->linkElement = $objectManager->getObject(
64+
$this->linkElement = $this->objectManager->getObject(
6565
Link::class,
6666
[
6767
'cmsPage' => $this->mockCmsPage,

0 commit comments

Comments
 (0)