class DefaultPackerTest in Commerce Shipping 8.2
@coversDefaultClass \Drupal\commerce_shipping\Packer\DefaultPacker @group commerce_shipping
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce_shipping\Unit\Packer\DefaultPackerTest
Expanded class hierarchy of DefaultPackerTest
File
- tests/
src/ Unit/ Packer/ DefaultPackerTest.php, line 28
Namespace
Drupal\Tests\commerce_shipping\Unit\PackerView source
class DefaultPackerTest extends UnitTestCase {
/**
* The default packer.
*
* @var \Drupal\commerce_shipping\Packer\DefaultPacker
*/
protected $packer;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$order_type = $this
->prophesize(OrderTypeInterface::class);
$order_type
->getThirdPartySetting('commerce_shipping', 'shipment_type')
->willReturn('default');
$order_type_storage = $this
->prophesize(EntityStorageInterface::class);
$order_type_storage
->load('default')
->willReturn($order_type
->reveal());
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager
->getStorage('commerce_order_type')
->willReturn($order_type_storage
->reveal());
$string_translation = $this
->prophesize(TranslationInterface::class);
$string_translation
->translateString(Argument::type(TranslatableMarkup::class))
->willReturn('Shipment #1');
$this->packer = new DefaultPacker($entity_type_manager
->reveal(), $string_translation
->reveal());
}
/**
* ::covers pack.
*/
public function testPack() {
$order_items = [];
$first_order_item = $this
->prophesize(OrderItemInterface::class);
$first_order_item
->id()
->willReturn(2001);
$first_order_item
->getPurchasedEntity()
->willReturn(NULL);
$first_order_item
->getQuantity()
->willReturn(1);
$order_items[] = $first_order_item
->reveal(1);
$weight_item = $this
->prophesize(MeasurementItem::class);
$weight_item
->toMeasurement()
->willReturn(new Weight('10', 'kg'));
$weight_list = $this
->prophesize(FieldItemListInterface::class);
$weight_list
->isEmpty()
->willReturn(FALSE);
$weight_list
->first()
->willReturn($weight_item
->reveal());
$purchased_entity = $this
->prophesize(PurchasableEntityInterface::class);
$purchased_entity
->id()
->willReturn(3001);
$purchased_entity
->getEntityTypeId()
->willReturn('commerce_product_variation');
$purchased_entity
->hasField('weight')
->willReturn(TRUE);
$purchased_entity
->get('weight')
->willReturn($weight_list
->reveal());
$purchased_entity = $purchased_entity
->reveal();
$second_order_item = $this
->prophesize(OrderItemInterface::class);
$second_order_item
->id()
->willReturn(2002);
$second_order_item
->getTitle()
->willReturn('T-shirt (red, small)');
$second_order_item
->getPurchasedEntity()
->willReturn($purchased_entity);
$second_order_item
->getUnitPrice()
->willReturn(new Price('15', 'USD'));
$second_order_item
->getQuantity()
->willReturn(3);
$order_items[] = $second_order_item
->reveal();
$third_order_item = $this
->prophesize(OrderItemInterface::class);
$third_order_item
->id()
->willReturn(2003);
$third_order_item
->getTitle()
->willReturn('T-shirt (black, small)');
$third_order_item
->getPurchasedEntity()
->willReturn($purchased_entity);
$third_order_item
->getUnitPrice()
->willReturn(new Price('15', 'USD'));
$third_order_item
->getQuantity()
->willReturn(0);
$order_items[] = $third_order_item
->reveal();
$order = $this
->prophesize(OrderInterface::class);
$order
->bundle()
->willReturn('default');
$order
->id()
->willReturn(2);
$order
->getItems()
->willReturn($order_items);
$order = $order
->reveal();
$shipping_profile = $this
->prophesize(ProfileInterface::class);
$shipping_profile
->id()
->willReturn(3);
$shipping_profile = $shipping_profile
->reveal();
$expected_proposed_shipment = new ProposedShipment([
'type' => 'default',
'order_id' => 2,
'title' => 'Shipment #1',
'items' => [
new ShipmentItem([
'order_item_id' => 2002,
'title' => 'T-shirt (red, small)',
'quantity' => 3,
'weight' => new Weight('30', 'kg'),
'declared_value' => new Price('45', 'USD'),
]),
],
'shipping_profile' => $shipping_profile,
]);
$result = $this->packer
->pack($order, $shipping_profile);
$this
->assertEquals([
$expected_proposed_shipment,
], $result);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultPackerTest:: |
protected | property | The default packer. | |
DefaultPackerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
DefaultPackerTest:: |
public | function | ::covers pack. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |