class ProposedShipmentTest in Commerce Shipping 8.2
@coversDefaultClass \Drupal\commerce_shipping\ProposedShipment @group commerce_shipping
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce_shipping\Unit\ProposedShipmentTest
Expanded class hierarchy of ProposedShipmentTest
File
- tests/
src/ Unit/ ProposedShipmentTest.php, line 16
Namespace
Drupal\Tests\commerce_shipping\UnitView source
class ProposedShipmentTest extends UnitTestCase {
/**
* The proposed shipment.
*
* @var \Drupal\commerce_shipping\ProposedShipment
*/
protected $proposedShipment;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$shipping_profile = $this
->prophesize(ProfileInterface::class);
$shipping_profile
->id()
->willReturn(11);
$this->proposedShipment = new ProposedShipment([
'type' => 'default',
'order_id' => 10,
'title' => 'Shipment from Narnia',
'items' => [
new ShipmentItem([
'order_item_id' => 10,
'title' => 'T-shirt (red, small)',
'quantity' => 1,
'weight' => new Weight('10', 'kg'),
'declared_value' => new Price('10', 'USD'),
]),
],
'shipping_profile' => $shipping_profile
->reveal(),
'package_type_id' => 'default',
'custom_fields' => [
'field_test' => 'value',
],
]);
}
/**
* @covers ::getType
*/
public function testGetType() {
$this
->assertEquals('default', $this->proposedShipment
->getType());
}
/**
* @covers ::getOrderId
*/
public function testGetOrderId() {
$this
->assertEquals(10, $this->proposedShipment
->getOrderId());
}
/**
* @covers ::getTitle
*/
public function testGetTitle() {
$this
->assertEquals('Shipment from Narnia', $this->proposedShipment
->getTitle());
}
/**
* @covers ::getItems
*/
public function testGetItems() {
$expected_items = [];
$expected_items[] = new ShipmentItem([
'order_item_id' => 10,
'title' => 'T-shirt (red, small)',
'quantity' => 1,
'weight' => new Weight('10', 'kg'),
'declared_value' => new Price('10', 'USD'),
]);
$items = $this->proposedShipment
->getItems();
$this
->assertArrayEquals($expected_items, $items);
}
/**
* @covers ::getShippingProfile
*/
public function testGetShippingProfile() {
$this
->assertEquals(11, $this->proposedShipment
->getShippingProfile()
->id());
}
/**
* @covers ::getPackageTypeId
*/
public function testGetPackageTypeId() {
$this
->assertEquals('default', $this->proposedShipment
->getPackageTypeId());
}
/**
* @covers ::getCustomFields
*/
public function testGetCustomFields() {
$this
->assertEquals([
'field_test' => 'value',
], $this->proposedShipment
->getCustomFields());
}
/**
* @covers ::__construct
*/
public function testMissingProperties() {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage('Missing required property "items".');
$proposed_shipment = new ProposedShipment([
'type' => 'default',
'order_id' => 10,
'title' => 'Test shipment',
'package_type_id' => 'default',
]);
}
/**
* @covers ::__construct
*/
public function testInvalidItems() {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage('Each shipment item under the "items" property must be an instance of ShipmentItem.');
$proposed_shipment = new ProposedShipment([
'type' => 'default',
'order_id' => 10,
'title' => 'Test shipment',
'items' => [
'invalid',
],
'shipping_profile' => $this
->prophesize(ProfileInterface::class)
->reveal(),
'package_type_id' => 'default',
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
ProposedShipmentTest:: |
protected | property | The proposed shipment. | |
ProposedShipmentTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ProposedShipmentTest:: |
public | function | @covers ::getCustomFields | |
ProposedShipmentTest:: |
public | function | @covers ::getItems | |
ProposedShipmentTest:: |
public | function | @covers ::getOrderId | |
ProposedShipmentTest:: |
public | function | @covers ::getPackageTypeId | |
ProposedShipmentTest:: |
public | function | @covers ::getShippingProfile | |
ProposedShipmentTest:: |
public | function | @covers ::getTitle | |
ProposedShipmentTest:: |
public | function | @covers ::getType | |
ProposedShipmentTest:: |
public | function | @covers ::__construct | |
ProposedShipmentTest:: |
public | function | @covers ::__construct | |
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. |