Skip to content

Commit 9394609

Browse files
glo23503devarul
authored andcommitted
ACP2E-1341: [On-Premise] Merchant Informed Core Issue Magento 2.4.4 main.ERROR: Environment emulation nesting is not allowed
1 parent 1b24ead commit 9394609

File tree

1 file changed

+11
-64
lines changed

1 file changed

+11
-64
lines changed

dev/tests/integration/testsuite/Magento/Sales/Model/Order/Email/Sender/ShipmentSenderTest.php

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,19 @@
1212
use Magento\Sales\Model\Order\Shipment;
1313
use Magento\Sales\Model\Order\ShipmentFactory;
1414
use Magento\TestFramework\Helper\Bootstrap;
15-
use Magento\Framework\App\State;
16-
use Magento\TestFramework\ErrorLog\Logger;
1715

1816
/**
1917
* @magentoAppArea frontend
2018
*
2119
* @deprecated since ShipmentSender is deprecated
2220
* @see \Magento\Sales\Model\Order\Email\Sender\ShipmentSender
23-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2421
*/
2522
class ShipmentSenderTest extends \PHPUnit\Framework\TestCase
2623
{
2724
private const NEW_CUSTOMER_EMAIL = 'new.customer@example.com';
2825
private const OLD_CUSTOMER_EMAIL = 'customer@example.com';
2926
private const ORDER_EMAIL = 'customer@example.com';
3027

31-
/** @var ObjectManagerInterface */
32-
private $objectManager;
33-
34-
/** @var Logger */
35-
private $logger;
36-
37-
/** @var int */
38-
private $minErrorDefaultValue;
39-
4028
/**
4129
* @var CustomerRepository
4230
*/
@@ -48,16 +36,7 @@ class ShipmentSenderTest extends \PHPUnit\Framework\TestCase
4836
protected function setUp(): void
4937
{
5038
parent::setUp();
51-
52-
$this->objectManager = Bootstrap::getObjectManager();
53-
$this->logger = $this->objectManager->get(Logger::class);
54-
$reflection = new \ReflectionClass(get_class($this->logger));
55-
$reflectionProperty = $reflection->getProperty('minimumErrorLevel');
56-
$reflectionProperty->setAccessible(true);
57-
$this->minErrorDefaultValue = $reflectionProperty->getValue($this->logger);
58-
$reflectionProperty->setValue($this->logger, 400);
59-
$this->logger->clearMessages();
60-
$this->customerRepository = $this->objectManager
39+
$this->customerRepository = Bootstrap::getObjectManager()
6140
->get(CustomerRepositoryInterface::class);
6241
}
6342

@@ -66,24 +45,19 @@ protected function setUp(): void
6645
*/
6746
public function testSend()
6847
{
69-
$this->objectManager->get(State::class)->setAreaCode('frontend');
70-
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
48+
Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
49+
$order = Bootstrap::getObjectManager()->create(\Magento\Sales\Model\Order::class);
7150
$order->loadByIncrementId('100000001');
7251
$order->setCustomerEmail('customer@example.com');
7352

74-
$shipment = $this->objectManager->get(ShipmentFactory::class)->create($order);
53+
$shipment = Bootstrap::getObjectManager()->get(ShipmentFactory::class)->create($order);
7554

7655
$this->assertEmpty($shipment->getEmailSent());
7756

78-
$orderSender = $this->objectManager
57+
$orderSender = Bootstrap::getObjectManager()
7958
->create(\Magento\Sales\Model\Order\Email\Sender\ShipmentSender::class);
8059
$result = $orderSender->send($shipment, true);
81-
$this->assertFalse(
82-
array_search(
83-
'Environment emulation nesting is not allowed.',
84-
array_column($this->logger->getMessages(), 'message')
85-
)
86-
);
60+
8761
$this->assertTrue($result);
8862

8963
$this->assertNotEmpty($shipment->getEmailSent());
@@ -109,12 +83,6 @@ public function testSendWhenCustomerEmailWasModified()
10983
$this->assertEmpty($shipment->getEmailSent());
11084
$result = $shipmentSender->send($shipment, true);
11185

112-
$this->assertFalse(
113-
array_search(
114-
'Environment emulation nesting is not allowed.',
115-
array_column($this->logger->getMessages(), 'message')
116-
)
117-
);
11886
$this->assertEquals(self::NEW_CUSTOMER_EMAIL, $shipmentIdentity->getCustomerEmail());
11987
$this->assertTrue($result);
12088
$this->assertNotEmpty($shipment->getEmailSent());
@@ -136,12 +104,6 @@ public function testSendWhenCustomerEmailWasNotModified()
136104
$this->assertEmpty($shipment->getEmailSent());
137105
$result = $shipmentSender->send($shipment, true);
138106

139-
$this->assertFalse(
140-
array_search(
141-
'Environment emulation nesting is not allowed.',
142-
array_column($this->logger->getMessages(), 'message')
143-
)
144-
);
145107
$this->assertEquals(self::OLD_CUSTOMER_EMAIL, $shipmentIdentity->getCustomerEmail());
146108
$this->assertTrue($result);
147109
$this->assertNotEmpty($shipment->getEmailSent());
@@ -166,12 +128,6 @@ public function testSendWithoutCustomer()
166128
$this->assertEmpty($shipment->getEmailSent());
167129
$result = $shipmentSender->send($shipment, true);
168130

169-
$this->assertFalse(
170-
array_search(
171-
'Environment emulation nesting is not allowed.',
172-
array_column($this->logger->getMessages(), 'message')
173-
)
174-
);
175131
$this->assertEquals(self::ORDER_EMAIL, $shipmentIdentity->getCustomerEmail());
176132
$this->assertTrue($result);
177133
$this->assertNotEmpty($shipment->getEmailSent());
@@ -184,16 +140,17 @@ public function testSendWithoutCustomer()
184140
*/
185141
public function testPackages()
186142
{
187-
$this->objectManager->get(State::class)->setAreaCode('frontend');
188-
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
143+
$objectManager = Bootstrap::getObjectManager();
144+
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
145+
$order = $objectManager->create(\Magento\Sales\Model\Order::class);
189146
$order->loadByIncrementId('100000001');
190147
$order->setCustomerEmail('customer@example.com');
191148
$items = [];
192149
foreach ($order->getItems() as $item) {
193150
$items[$item->getId()] = $item->getQtyOrdered();
194151
}
195152
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
196-
$shipment = $this->objectManager->get(ShipmentFactory::class)->create($order, $items);
153+
$shipment = $objectManager->get(ShipmentFactory::class)->create($order, $items);
197154
$packages = [['1'], ['2']];
198155
$shipment->setPackages($packages);
199156
$this->assertEquals($packages, $shipment->getPackages());
@@ -205,7 +162,7 @@ public function testPackages()
205162

206163
private function createShipment(Order $order): Shipment
207164
{
208-
$shipment = $this->objectManager->create(
165+
$shipment = Bootstrap::getObjectManager()->create(
209166
Shipment::class
210167
);
211168
$shipment->setOrder($order);
@@ -239,14 +196,4 @@ private function createShipmentSender(ShipmentIdentity $shipmentIdentity): Shipm
239196
]
240197
);
241198
}
242-
243-
/**
244-
* @inheritdoc
245-
*/
246-
protected function tearDown(): void
247-
{
248-
$reflectionProperty = new \ReflectionProperty(get_class($this->logger), 'minimumErrorLevel');
249-
$reflectionProperty->setAccessible(true);
250-
$reflectionProperty->setValue($this->logger, $this->minErrorDefaultValue);
251-
}
252199
}

0 commit comments

Comments
 (0)