Skip to content

Commit 47df339

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

File tree

9 files changed

+126
-5
lines changed

9 files changed

+126
-5
lines changed

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/ExtendTest.php

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

1010
use Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes\Extend;
1111
use Magento\Catalog\Model\Product;
12+
use Magento\Directory\Helper\Data as DirectoryHelper;
1213
use Magento\Framework\Data\Form;
1314
use Magento\Framework\Data\FormFactory;
15+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1416
use Magento\Framework\Registry;
1517
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1618
use PHPUnit\Framework\Constraint\ArrayHasKey;
@@ -41,6 +43,17 @@ protected function setUp(): void
4143
)->disableOriginalConstructor()
4244
->getMock();
4345
$this->objectManagerHelper = new ObjectManager($this);
46+
$objects = [
47+
[
48+
JsonHelper::class,
49+
$this->createMock(JsonHelper::class)
50+
],
51+
[
52+
DirectoryHelper::class,
53+
$this->createMock(DirectoryHelper::class)
54+
]
55+
];
56+
$this->objectManagerHelper->prepareObjectManager($objects);
4457
$this->object = $this->objectManagerHelper->getObject(
4558
Extend::class,
4659
['registry' => $this->registry, 'formFactory' => $this->formFactory]

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
namespace Magento\Bundle\Test\Unit\Block\Adminhtml\Sales\Order\Items;
99

1010
use Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer;
11+
use Magento\Directory\Helper\Data as DirectoryHelper;
12+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1113
use Magento\Framework\Serialize\Serializer\Json;
1214
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1315
use Magento\Sales\Model\Order\Creditmemo;
@@ -40,6 +42,17 @@ protected function setUp(): void
4042
->getMock();
4143
$this->serializer = $this->createMock(Json::class);
4244
$objectManager = new ObjectManager($this);
45+
$objects = [
46+
[
47+
JsonHelper::class,
48+
$this->createMock(JsonHelper::class)
49+
],
50+
[
51+
DirectoryHelper::class,
52+
$this->createMock(DirectoryHelper::class)
53+
]
54+
];
55+
$objectManager->prepareObjectManager($objects);
4356
$this->model = $objectManager->getObject(
4457
Renderer::class,
4558
['serializer' => $this->serializer]
@@ -318,7 +331,7 @@ public function testGetValueHtmlWithoutShipmentSeparately($qty)
318331
{
319332
$model = $this->getMockBuilder(Renderer::class)
320333
->disableOriginalConstructor()
321-
->setMethods(['escapeHtml', 'isShipmentSeparately', 'getSelectionAttributes', 'isChildCalculated'])
334+
->onlyMethods(['escapeHtml', 'isShipmentSeparately', 'getSelectionAttributes', 'isChildCalculated'])
322335
->getMock();
323336
$model->expects($this->any())->method('escapeHtml')->willReturn('Test');
324337
$model->expects($this->any())->method('isShipmentSeparately')->willReturn(false);

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
namespace Magento\Bundle\Test\Unit\Block\Adminhtml\Sales\Order\View\Items;
1010

1111
use Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items\Renderer;
12+
use Magento\Directory\Helper\Data as DirectoryHelper;
13+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1214
use Magento\Framework\Serialize\Serializer\Json;
1315
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1416
use Magento\Sales\Model\Order\Item;
@@ -35,6 +37,17 @@ protected function setUp(): void
3537
->getMock();
3638
$this->serializer = $this->createMock(Json::class);
3739
$objectManager = new ObjectManager($this);
40+
$objects = [
41+
[
42+
JsonHelper::class,
43+
$this->createMock(JsonHelper::class)
44+
],
45+
[
46+
DirectoryHelper::class,
47+
$this->createMock(DirectoryHelper::class)
48+
]
49+
];
50+
$objectManager->prepareObjectManager($objects);
3851
$this->model = $objectManager->getObject(
3952
Renderer::class,
4053
['serializer' => $this->serializer]
@@ -232,7 +245,7 @@ public function testGetValueHtmlWithoutShipmentSeparately($qty)
232245
{
233246
$model = $this->getMockBuilder(Renderer::class)
234247
->disableOriginalConstructor()
235-
->setMethods(['escapeHtml', 'isShipmentSeparately', 'getSelectionAttributes', 'isChildCalculated'])
248+
->onlyMethods(['escapeHtml', 'isShipmentSeparately', 'getSelectionAttributes', 'isChildCalculated'])
236249
->getMock();
237250
$model->expects($this->any())->method('escapeHtml')->willReturn('Test');
238251
$model->expects($this->any())->method('isShipmentSeparately')->willReturn(false);

app/code/Magento/Bundle/Test/Unit/Model/Option/SaveActionTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Magento\Framework\EntityManager\EntityMetadataInterface;
1919
use PHPUnit\Framework\MockObject\MockObject;
2020
use PHPUnit\Framework\TestCase;
21+
use Magento\Store\Model\StoreManagerInterface;
22+
use Magento\Bundle\Api\ProductLinkManagementAddChildrenInterface;
2123

2224
class SaveActionTest extends TestCase
2325
{
@@ -51,6 +53,16 @@ class SaveActionTest extends TestCase
5153
*/
5254
private $saveAction;
5355

56+
/**
57+
* @var StoreManagerInterface
58+
*/
59+
private $storeManager;
60+
61+
/**
62+
* @var ProductLinkManagementAddChildrenInterface
63+
*/
64+
private $addChildren;
65+
5466
protected function setUp(): void
5567
{
5668
$this->linkManagement = $this->getMockBuilder(ProductLinkManagementInterface::class)
@@ -65,6 +77,12 @@ protected function setUp(): void
6577
$this->optionResource = $this->getMockBuilder(OptionResource::class)
6678
->disableOriginalConstructor()
6779
->getMock();
80+
$this->addChildren = $this->getMockBuilder(ProductLinkManagementAddChildrenInterface::class)
81+
->disableOriginalConstructor()
82+
->getMock();
83+
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
84+
->disableOriginalConstructor()
85+
->getMock();
6886
$this->product = $this->getMockBuilder(ProductInterface::class)
6987
->addMethods(['getStoreId', 'getData', 'setIsRelationsChanged'])
7088
->getMockForAbstractClass();
@@ -73,7 +91,10 @@ protected function setUp(): void
7391
$this->optionResource,
7492
$this->metadataPool,
7593
$this->type,
76-
$this->linkManagement
94+
$this->linkManagement,
95+
$this->storeManager,
96+
$this->addChildren
97+
7798
);
7899
}
79100

app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/SelectionTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\DB\Adapter\AdapterInterface;
1515
use Magento\Framework\EntityManager\MetadataPool;
1616
use Magento\Framework\Model\ResourceModel\Db\Context;
17+
use Magento\Framework\EntityManager\EntityManager;
1718

1819
class SelectionTest extends TestCase
1920
{
@@ -27,6 +28,11 @@ class SelectionTest extends TestCase
2728
*/
2829
private MetadataPool $metadataPool;
2930

31+
/**
32+
* @var EntityManager
33+
*/
34+
private EntityManager $entityManager;
35+
3036
/**
3137
* @inheritdoc
3238
*/
@@ -36,6 +42,7 @@ protected function setUp(): void
3642

3743
$this->context = $this->createMock(Context::class);
3844
$this->metadataPool = $this->createMock(MetadataPool::class);
45+
$this->entityManager = $this->createMock(EntityManager::class);
3946
}
4047

4148
public function testSaveSelectionPrice()
@@ -82,7 +89,7 @@ public function testSaveSelectionPrice()
8289
->willReturn('catalog_product_bundle_selection_price');
8390
$this->context->expects($this->once())->method('getResources')->willReturn($parentResources);
8491

85-
$selection = new ResourceSelection($this->context, $this->metadataPool, 'test_connection_name');
92+
$selection = new ResourceSelection($this->context, $this->metadataPool, 'test_connection_name',$this->entityManager);
8693
$selection->saveSelectionPrice($item);
8794
}
8895
}

app/code/Magento/Captcha/Test/Unit/Helper/DataTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use Magento\Store\Model\Website;
2424
use PHPUnit\Framework\MockObject\MockObject;
2525
use PHPUnit\Framework\TestCase;
26+
use Magento\Framework\Math\Random;
27+
use Magento\Authorization\Model\UserContextInterface;
2628

2729
/**
2830
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -91,7 +93,9 @@ public function testGetCaptcha()
9193
$this->createMock(SessionManager::class),
9294
$this->createMock(Data::class),
9395
$this->createPartialMock(LogFactory::class, ['create']),
94-
'user_create'
96+
'user_create',
97+
$this->createMock(Random::class),
98+
$this->createMock(UserContextInterface::class)
9599
)
96100
);
97101

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Category/AbstractCategoryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use Magento\Backend\Block\Template\Context;
1111
use Magento\Catalog\Block\Adminhtml\Category\AbstractCategory;
1212
use Magento\Catalog\Model\Category;
13+
use Magento\Directory\Helper\Data as DirectoryHelper;
1314
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1416
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1517
use Magento\Framework\UrlInterface;
1618
use Magento\Store\Model\Store;
@@ -59,6 +61,18 @@ protected function setUp(): void
5961
{
6062
$this->objectManager = new ObjectManager($this);
6163

64+
$objects = [
65+
[
66+
JsonHelper::class,
67+
$this->createMock(JsonHelper::class)
68+
],
69+
[
70+
DirectoryHelper::class,
71+
$this->createMock(DirectoryHelper::class)
72+
]
73+
];
74+
$this->objectManager->prepareObjectManager($objects);
75+
6276
$this->contextMock = $this->createMock(Context::class);
6377

6478
$this->requestMock = $this->getMockBuilder(

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Advanced;
1111
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1212
use Magento\Config\Model\Config\Source\Yesno;
13+
use Magento\Directory\Helper\Data as DirectoryHelper;
1314
use Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker;
1415
use Magento\Eav\Helper\Data as EavHelper;
1516
use Magento\Eav\Model\Entity\Type as EntityType;
@@ -19,6 +20,7 @@
1920
use Magento\Framework\Data\FormFactory;
2021
use Magento\Framework\Filesystem;
2122
use Magento\Framework\Filesystem\Directory\ReadInterface;
23+
use Magento\Framework\Json\Helper\Data as JsonHelper;
2224
use Magento\Framework\Registry;
2325
use Magento\Framework\Stdlib\DateTime;
2426
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
@@ -79,6 +81,18 @@ class AdvancedTest extends TestCase
7981
protected function setUp(): void
8082
{
8183
$objectManager = new ObjectManager($this);
84+
$objects = [
85+
[
86+
JsonHelper::class,
87+
$this->createMock(JsonHelper::class)
88+
],
89+
[
90+
DirectoryHelper::class,
91+
$this->createMock(DirectoryHelper::class)
92+
]
93+
];
94+
$objectManager->prepareObjectManager($objects);
95+
8296
$this->registry = $this->createMock(Registry::class);
8397
$this->formFactory = $this->createMock(FormFactory::class);
8498
$this->yesNo = $this->createMock(Yesno::class);

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Attribute/GridTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,35 @@
1010
use Magento\Backend\Block\Template\Context;
1111
use Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid;
1212
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
13+
use Magento\Directory\Helper\Data as DirectoryHelper;
1314
use Magento\Framework\Filesystem;
15+
use Magento\Framework\Json\Helper\Data as JsonHelper;
1416
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1517
use Magento\Framework\UrlInterface;
1618
use PHPUnit\Framework\TestCase;
1719

1820
class GridTest extends TestCase
1921
{
22+
/**
23+
* @inheritdoc
24+
*/
25+
protected function setUp(): void
26+
{
27+
$objectManager = new ObjectManager($this);
28+
29+
$objects = [
30+
[
31+
JsonHelper::class,
32+
$this->createMock(JsonHelper::class)
33+
],
34+
[
35+
DirectoryHelper::class,
36+
$this->createMock(DirectoryHelper::class)
37+
]
38+
];
39+
$objectManager->prepareObjectManager($objects);
40+
}
41+
2042
public function testGetRowUrl()
2143
{
2244
$attribute = $this->createMock(Attribute::class);

0 commit comments

Comments
 (0)