ShipmentDocumentFactoryTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Sales\Model\Order;
  8. use Magento\Sales\Api\Data\ShipmentCreationArgumentsExtensionInterfaceFactory;
  9. use Magento\Sales\Api\Data\ShipmentCreationArgumentsInterface;
  10. use Magento\Sales\Model\Order;
  11. use Magento\TestFramework\Helper\Bootstrap;
  12. use PHPUnit\Framework\TestCase;
  13. /**
  14. * Provide tests for shipment document factory.
  15. */
  16. class ShipmentDocumentFactoryTest extends TestCase
  17. {
  18. /**
  19. * @var Order
  20. */
  21. private $order;
  22. /**
  23. * @var ShipmentDocumentFactory
  24. */
  25. private $shipmentDocumentFactory;
  26. /**
  27. * @var ShipmentCreationArgumentsInterface
  28. */
  29. private $shipmentCreationArgumentsInterface;
  30. /**
  31. * @var ShipmentCreationArgumentsExtensionInterfaceFactory
  32. */
  33. private $shipmentCreationArgumentsExtensionInterfaceFactory;
  34. /**
  35. * @inheritdoc
  36. */
  37. protected function setUp(): void
  38. {
  39. $objectManager = Bootstrap::getObjectManager();
  40. $this->order = $objectManager->create(Order::class);
  41. $this->shipmentDocumentFactory = $objectManager->create(ShipmentDocumentFactory::class);
  42. $this->shipmentCreationArgumentsInterface = $objectManager
  43. ->create(ShipmentCreationArgumentsInterface::class);
  44. $this->shipmentCreationArgumentsExtensionInterfaceFactory = $objectManager
  45. ->create(ShipmentCreationArgumentsExtensionInterfaceFactory::class);
  46. }
  47. /**
  48. * Create shipment with shipment creation arguments.
  49. *
  50. * @magentoDataFixture Magento/Sales/_files/order.php
  51. */
  52. public function testCreate(): void
  53. {
  54. $order = $this->order->loadByIncrementId('100000001');
  55. $argumentsExtensionAttributes = $this->shipmentCreationArgumentsExtensionInterfaceFactory->create([
  56. 'data' => ['test_attribute_value' => 'test_value']
  57. ]);
  58. $this->shipmentCreationArgumentsInterface->setExtensionAttributes($argumentsExtensionAttributes);
  59. $shipment = $this->shipmentDocumentFactory->create(
  60. $order,
  61. [],
  62. [],
  63. null,
  64. false,
  65. [],
  66. $this->shipmentCreationArgumentsInterface
  67. );
  68. $shipmentExtensionAttributes = $shipment->getExtensionAttributes();
  69. self::assertEquals('test_value', $shipmentExtensionAttributes->getTestAttributeValue());
  70. }
  71. }