class ShipmentItemTest in Commerce Shipping 8.2
@coversDefaultClass \Drupal\commerce_shipping\ShipmentItem @group commerce_shipping
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce_shipping\Unit\ShipmentItemTest
Expanded class hierarchy of ShipmentItemTest
File
- tests/
src/ Unit/ ShipmentItemTest.php, line 14
Namespace
Drupal\Tests\commerce_shipping\UnitView source
class ShipmentItemTest extends UnitTestCase {
/**
* The shipment item.
*
* @var \Drupal\commerce_shipping\ShipmentItem
*/
protected $shipmentItem;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->shipmentItem = new ShipmentItem([
'order_item_id' => 10,
'title' => 'T-shirt (red, small)',
'quantity' => 1,
'weight' => new Weight('10', 'kg'),
'declared_value' => new Price('8', 'USD'),
'tariff_code' => '7113.19.0000',
]);
}
/**
* @covers ::getOrderItemId
*/
public function testGetOrderItemId() {
$this
->assertEquals(10, $this->shipmentItem
->getOrderItemId());
}
/**
* @covers ::getTitle
*/
public function testGetTitle() {
$this
->assertEquals('T-shirt (red, small)', $this->shipmentItem
->getTitle());
}
/**
* @covers ::getQuantity
*/
public function testGetQuantity() {
$this
->assertEquals(1, $this->shipmentItem
->getQuantity());
}
/**
* @covers ::getWeight
*/
public function testGetWeight() {
$this
->assertEquals(new Weight('10', 'kg'), $this->shipmentItem
->getWeight());
}
/**
* @covers ::getDeclaredValue
*/
public function testGetDeclaredValue() {
$this
->assertEquals(new Price('8', 'USD'), $this->shipmentItem
->getDeclaredValue());
}
/**
* @covers ::getTariffCode
*/
public function testGetTariffCode() {
$this
->assertEquals('7113.19.0000', $this->shipmentItem
->getTariffCode());
}
/**
* @covers ::__construct
*/
public function testMissingProperties() {
$this
->expectException(\InvalidArgumentException::class);
$this
->expectExceptionMessage('Missing required property "declared_value".');
$proposed_shipment = new ShipmentItem([
'order_item_id' => 10,
'title' => 'T-shirt (red, small)',
'quantity' => 1,
'weight' => new Weight('10', 'kg'),
]);
}
}
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. | |
ShipmentItemTest:: |
protected | property | The shipment item. | |
ShipmentItemTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ShipmentItemTest:: |
public | function | @covers ::getDeclaredValue | |
ShipmentItemTest:: |
public | function | @covers ::getOrderItemId | |
ShipmentItemTest:: |
public | function | @covers ::getQuantity | |
ShipmentItemTest:: |
public | function | @covers ::getTariffCode | |
ShipmentItemTest:: |
public | function | @covers ::getTitle | |
ShipmentItemTest:: |
public | function | @covers ::getWeight | |
ShipmentItemTest:: |
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. |