Skip to content

Commit 7d4b8ca

Browse files
ACQE-8964: Create Shipment for Offline Payment Methods with Async Notification
- Updated few coding standard issues
1 parent cc06bc9 commit 7d4b8ca

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

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

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Framework\Mail\EmailMessageInterface;
2121
use Magento\Quote\Test\Fixture\AddProductToCart as AddProductToCartFixture;
2222
use Magento\Quote\Test\Fixture\GuestCart as GuestCartFixture;
23+
use Magento\Sales\Api\Data\ShipmentInterface;
2324
use Magento\Sales\Api\InvoiceRepositoryInterface;
2425
use Magento\Sales\Api\OrderRepositoryInterface;
2526
use Magento\Sales\Model\Order;
@@ -139,21 +140,33 @@ private function createInvoiceForOrder(Order $order): void
139140
}
140141

141142
/**
142-
* Creates a shipment for the order from fixtures.
143+
* Gets order from fixture storage.
143144
*
144-
* @return \Magento\Sales\Api\Data\ShipmentInterface
145-
* @throws LocalizedException
145+
* @return Order
146146
*/
147-
private function createShipmentForOrder()
147+
private function getOrderFromFixture(): Order
148148
{
149149
$fixtures = DataFixtureStorageManager::getStorage();
150150
/** @var Order $fixtureOrder */
151151
$fixtureOrder = $fixtures->get('order');
152152
$objectManager = Bootstrap::getObjectManager();
153153
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
154+
return $orderRepository->get((int)$fixtureOrder->getEntityId());
155+
}
156+
157+
/**
158+
* Creates a shipment for the order from fixtures.
159+
*
160+
* @return ShipmentInterface
161+
* @throws LocalizedException
162+
*/
163+
private function createShipmentForOrder(): ShipmentInterface
164+
{
165+
$order = $this->getOrderFromFixture();
166+
$objectManager = Bootstrap::getObjectManager();
154167
$shipmentRepository = $objectManager->get(ShipmentRepositoryInterface::class);
155168
$shipmentFactory = $objectManager->get(ShipmentFactory::class);
156-
$order = $orderRepository->get((int)$fixtureOrder->getEntityId());
169+
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
157170
$this->createInvoiceForOrder($order);
158171
$quantities = $this->calculateShippableQuantities($order);
159172
$shipment = $shipmentFactory->create($order, $quantities);
@@ -200,9 +213,22 @@ private function assertShipmentEmailContent(EmailMessageInterface $email): void
200213
$email->getSubject(),
201214
'Email subject should contain shipment confirmation text.'
202215
);
216+
217+
// Assert getTo() returns a non-empty array
218+
$recipients = $email->getTo();
219+
$this->assertNotEmpty(
220+
$recipients,
221+
'Email should have at least one recipient.'
222+
);
223+
$this->assertIsArray(
224+
$recipients,
225+
'Email recipients should be returned as an array.'
226+
);
227+
228+
// Now safely access the first recipient
203229
$this->assertEquals(
204230
'async-shipment@example.com',
205-
$email->getTo()[0]->getEmail(),
231+
$recipients[0]->getEmail(),
206232
'Email should be sent to the customer email address.'
207233
);
208234
}

0 commit comments

Comments
 (0)