Skip to content

Commit cc81101

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

File tree

13 files changed

+211
-18
lines changed

13 files changed

+211
-18
lines changed

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Edit/Tab/InventoryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Magento\CatalogInventory\Api\StockRegistryInterface;
1717
use Magento\CatalogInventory\Model\Source\Backorders;
1818
use Magento\CatalogInventory\Model\Source\Stock;
19+
use Magento\Directory\Helper\Data as DirectoryHelper;
20+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1921
use Magento\Framework\Module\Manager;
2022
use Magento\Framework\Registry;
2123
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
@@ -83,6 +85,18 @@ protected function setUp(): void
8385
{
8486
$objectManager = new ObjectManager($this);
8587

88+
$objects = [
89+
[
90+
JsonHelper::class,
91+
$this->createMock(JsonHelper::class)
92+
],
93+
[
94+
DirectoryHelper::class,
95+
$this->createMock(DirectoryHelper::class)
96+
]
97+
];
98+
$objectManager->prepareObjectManager($objects);
99+
86100
$this->contextMock = $this->createPartialMock(
87101
Context::class,
88102
['getRequest', 'getStoreManager']

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/CategoryTest.php

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

1010
use Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Category;
1111
use Magento\Framework\AuthorizationInterface;
12+
use Magento\Framework\Math\Random;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Framework\View\Helper\SecureHtmlRenderer;
1315
use PHPUnit\Framework\TestCase;
1416

1517
class CategoryTest extends TestCase
@@ -30,6 +32,17 @@ protected function setUp(): void
3032
->disableOriginalConstructor()
3133
->getMockForAbstractClass();
3234
$this->objectManager = new ObjectManager($this);
35+
$objects = [
36+
[
37+
SecureHtmlRenderer::class,
38+
$this->createMock(SecureHtmlRenderer::class)
39+
],
40+
[
41+
Random::class,
42+
$this->createMock(Random::class)
43+
]
44+
];
45+
$this->objectManager->prepareObjectManager($objects);
3346
}
3447

3548
/**

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/WeightTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use Magento\Framework\Data\Form\Element\Factory;
1414
use Magento\Framework\Data\Form\Element\Radios;
1515
use Magento\Framework\Locale\Format;
16+
use Magento\Framework\Math\Random;
1617
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use Magento\Framework\View\Helper\SecureHtmlRenderer;
1719
use PHPUnit\Framework\MockObject\MockObject;
1820
use PHPUnit\Framework\TestCase;
1921

@@ -46,6 +48,18 @@ class WeightTest extends TestCase
4648

4749
protected function setUp(): void
4850
{
51+
$objectManager = new ObjectManager($this);
52+
$objects = [
53+
[
54+
SecureHtmlRenderer::class,
55+
$this->createMock(SecureHtmlRenderer::class)
56+
],
57+
[
58+
Random::class,
59+
$this->createMock(Random::class)
60+
]
61+
];
62+
$objectManager->prepareObjectManager($objects);
4963
$this->weightSwitcher = $this->getMockBuilder(Radios::class)
5064
->addMethods(['setName', 'setLabel'])
5165
->onlyMethods(['setId', 'setForm'])
@@ -72,7 +86,7 @@ protected function setUp(): void
7286
['create']
7387
);
7488

75-
$this->_model = (new ObjectManager($this))->getObject(
89+
$this->_model = $objectManager->getObject(
7690
Weight::class,
7791
[
7892
'factoryElement' => $this->factory,

app/code/Magento/Catalog/Test/Unit/Block/Widget/LinkTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
1414
use Magento\Framework\App\Config\ReinitableConfigInterface;
1515
use Magento\Framework\App\Config\ScopeConfigInterface;
16+
use Magento\Framework\Math\Random;
1617
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1718
use Magento\Framework\Url;
1819
use Magento\Framework\Url\ModifierInterface;
1920
use Magento\Framework\View\Element\Template\Context;
21+
use Magento\Framework\View\Helper\SecureHtmlRenderer;
2022
use Magento\Store\Model\Store;
2123
use Magento\Store\Model\StoreManagerInterface;
2224
use Magento\UrlRewrite\Model\UrlFinderInterface;
@@ -57,6 +59,19 @@ class LinkTest extends TestCase
5759
*/
5860
protected function setUp(): void
5961
{
62+
$objectManager = new ObjectManager($this);
63+
$objects = [
64+
[
65+
SecureHtmlRenderer::class,
66+
$this->createMock(SecureHtmlRenderer::class)
67+
],
68+
[
69+
Random::class,
70+
$this->createMock(Random::class)
71+
]
72+
];
73+
$objectManager->prepareObjectManager($objects);
74+
6075
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
6176
$this->urlFinder = $this->getMockForAbstractClass(UrlFinderInterface::class);
6277

@@ -68,7 +83,7 @@ protected function setUp(): void
6883
$this->entityResource =
6984
$this->createMock(AbstractResource::class);
7085

71-
$this->block = (new ObjectManager($this))->getObject(
86+
$this->block = $objectManager->getObject(
7287
Link::class,
7388
[
7489
'context' => $context,

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99

1010
use Magento\Backend\App\Action\Context;
1111
use Magento\Backend\Model\Auth;
12+
use Magento\Backend\Model\Auth\Session;
1213
use Magento\Backend\Model\Auth\StorageInterface;
1314
use Magento\Backend\Model\View\Result\Redirect;
1415
use Magento\Backend\Model\View\Result\RedirectFactory;
1516
use Magento\Catalog\Api\CategoryRepositoryInterface;
1617
use Magento\Catalog\Controller\Adminhtml\Category\Delete;
1718
use Magento\Catalog\Model\Category;
19+
use Magento\Cms\Model\Wysiwyg\Config;
1820
use Magento\Framework\App\RequestInterface;
1921
use Magento\Framework\App\ResponseInterface;
2022
use Magento\Framework\Event\ManagerInterface;
23+
use Magento\Framework\Registry;
2124
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
25+
use Magento\Store\Model\StoreManagerInterface;
2226
use PHPUnit\Framework\MockObject\MockObject;
2327
use PHPUnit\Framework\TestCase;
2428

@@ -44,6 +48,29 @@ class DeleteTest extends TestCase
4448

4549
protected function setUp(): void
4650
{
51+
52+
$objectManager = new ObjectManagerHelper($this);
53+
54+
$objects = [
55+
[
56+
StoreManagerInterface::class,
57+
$this->createMock(StoreManagerInterface::class)
58+
],
59+
[
60+
Registry::class,
61+
$this->createMock(Registry::class)
62+
],
63+
[
64+
Config::class,
65+
$this->createMock(Config::class)
66+
],
67+
[
68+
Session::class,
69+
$this->createMock(Session::class)
70+
]
71+
];
72+
$objectManager->prepareObjectManager($objects);
73+
4774
$context = $this->createMock(Context::class);
4875
$resultRedirectFactory = $this->createPartialMock(
4976
RedirectFactory::class,
@@ -111,7 +138,7 @@ protected function setUp(): void
111138
$this->resultRedirect = $this->createMock(Redirect::class);
112139
$resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
113140

114-
$this->unit = (new ObjectManagerHelper($this))->getObject(
141+
$this->unit = $objectManager->getObject(
115142
Delete::class,
116143
[
117144
'context' => $context,

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
use Magento\Store\Model\StoreManagerInterface;
2626
use PHPUnit\Framework\MockObject\MockObject;
2727
use PHPUnit\Framework\TestCase;
28+
use Magento\Framework\Stdlib\DateTime\Filter\Date;
29+
use Magento\Framework\Registry;
30+
use Magento\Cms\Model\Wysiwyg\Config;
2831

2932
/**
3033
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -114,7 +117,31 @@ class EditTest extends TestCase
114117
*/
115118
protected function setUp(): void
116119
{
117-
$this->objectManager = new ObjectManager($this);
120+
$objectManager = new ObjectManager($this);
121+
122+
$objects = [
123+
[
124+
Date::class,
125+
$this->createMock(Date::class)
126+
],
127+
[
128+
StoreManagerInterface::class,
129+
$this->createMock(StoreManagerInterface::class)
130+
],
131+
[
132+
Registry::class,
133+
$this->createMock(Registry::class)
134+
],
135+
[
136+
Config::class,
137+
$this->createMock(Config::class)
138+
],
139+
[
140+
Session::class,
141+
$this->createMock(Session::class)
142+
]
143+
];
144+
$objectManager->prepareObjectManager($objects);
118145

119146
$this->categoryMock = $this->createPartialMock(
120147
Category::class,
@@ -214,7 +241,7 @@ protected function setUp(): void
214241
->method('getResultRedirectFactory')
215242
->willReturn($this->resultRedirectFactoryMock);
216243

217-
$this->edit = $this->objectManager->getObject(
244+
$this->edit = $objectManager->getObject(
218245
Edit::class,
219246
[
220247
'context' => $this->contextMock,

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,28 @@ class SaveTest extends TestCase
8989
*/
9090
protected function setUp(): void
9191
{
92-
$this->objectManager = new ObjectManager($this);
92+
$objectManager = new ObjectManager($this);
93+
94+
$objects = [
95+
[
96+
StoreManagerInterface::class,
97+
$this->createMock(StoreManagerInterface::class)
98+
],
99+
[
100+
Registry::class,
101+
$this->createMock(Registry::class)
102+
],
103+
[
104+
Config::class,
105+
$this->createMock(Config::class)
106+
],
107+
[
108+
Session::class,
109+
$this->createMock(Session::class)
110+
]
111+
];
112+
$objectManager->prepareObjectManager($objects);
113+
93114
$this->resultRedirectFactoryMock = $this->createPartialMock(
94115
RedirectFactory::class,
95116
['create']
@@ -130,7 +151,7 @@ protected function setUp(): void
130151
['addSuccessMessage', 'getMessages']
131152
);
132153

133-
$this->save = $this->objectManager->getObject(
154+
$this->save = $objectManager->getObject(
134155
Save::class,
135156
[
136157
'request' => $this->requestMock,

app/code/Magento/Catalog/Test/Unit/Helper/Product/ConfigurationTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\Stdlib\StringUtils;
1919
use PHPUnit\Framework\MockObject\MockObject;
2020
use PHPUnit\Framework\TestCase;
21+
use Magento\Framework\Escaper;
2122

2223
class ConfigurationTest extends TestCase
2324
{
@@ -31,20 +32,27 @@ class ConfigurationTest extends TestCase
3132
*/
3233
protected $helper;
3334

35+
/**
36+
* @var Escaper|MockObject
37+
*/
38+
private $escaper;
39+
3440
protected function setUp(): void
3541
{
3642
$contextMock = $this->createMock(Context::class);
3743
$optionFactoryMock = $this->createMock(OptionFactory::class);
3844
$filterManagerMock = $this->createMock(FilterManager::class);
3945
$stringUtilsMock = $this->createMock(StringUtils::class);
4046
$this->serializer = $this->createMock(Json::class);
47+
$this->escaper = $this->createMock(Escaper::class);
4148

4249
$this->helper = new Configuration(
4350
$contextMock,
4451
$optionFactoryMock,
4552
$filterManagerMock,
4653
$stringUtilsMock,
47-
$this->serializer
54+
$this->serializer,
55+
$this->escaper
4856
);
4957
}
5058

app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Fulltext/CollectionTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77

88
namespace Magento\CatalogSearch\Test\Unit\Model\ResourceModel\Fulltext;
99

10+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer;
11+
use Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver;
12+
use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler;
13+
use Magento\Catalog\Model\ResourceModel\Category;
1014
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation;
1115
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
16+
use Magento\Catalog\Model\ResourceModel\Product\Gallery;
1217
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
1318
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchCriteriaResolverFactory;
1419
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchCriteriaResolverInterface;
1520
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierFactory;
1621
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverFactory;
1722
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\SearchResultApplierInterface;
1823
use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection\TotalRecordsResolverInterface;
24+
use Magento\CatalogUrlRewrite\Model\Storage\DbStorage;
1925
use Magento\Eav\Model\Entity\AbstractEntity;
2026
use Magento\Framework\Api\Filter;
2127
use Magento\Framework\Api\FilterBuilder;
@@ -24,6 +30,7 @@
2430
use Magento\Framework\App\Config\ScopeConfigInterface;
2531
use Magento\Framework\DB\Adapter\Pdo\Mysql;
2632
use Magento\Framework\DB\Select;
33+
use Magento\Framework\Indexer\DimensionFactory;
2734
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2835
use Magento\Framework\Validator\UniversalFactory;
2936
use Magento\Search\Api\SearchInterface;
@@ -102,6 +109,38 @@ protected function setUp(): void
102109
$this->criteriaBuilder = $this->getCriteriaBuilder();
103110
$this->filterBuilder = $this->getFilterBuilder();
104111

112+
$objects = [
113+
[
114+
TableMaintainer::class,
115+
$this->createMock(TableMaintainer::class)
116+
],
117+
[
118+
PriceTableResolver::class,
119+
$this->createMock(PriceTableResolver::class)
120+
],
121+
[
122+
DimensionFactory::class,
123+
$this->createMock(DimensionFactory::class)
124+
],
125+
[
126+
Category::class,
127+
$this->createMock(Category::class)
128+
],
129+
[
130+
DbStorage::class,
131+
$this->createMock(DbStorage::class)
132+
],
133+
[
134+
GalleryReadHandler::class,
135+
$this->createMock(GalleryReadHandler::class)
136+
],
137+
[
138+
Gallery::class,
139+
$this->createMock(Gallery::class)
140+
]
141+
];
142+
$this->objectManager->prepareObjectManager($objects);
143+
105144
$productLimitationMock = $this->createMock(ProductLimitation::class);
106145
$productLimitationFactoryMock = $this->getMockBuilder(ProductLimitationFactory::class)
107146
->disableOriginalConstructor()

0 commit comments

Comments
 (0)