You are here

class ShipmentItemTest in Commerce Shipping 8.2

@coversDefaultClass \Drupal\commerce_shipping\ShipmentItem @group commerce_shipping

Hierarchy

Expanded class hierarchy of ShipmentItemTest

File

tests/src/Unit/ShipmentItemTest.php, line 14

Namespace

Drupal\Tests\commerce_shipping\Unit
View 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

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
ShipmentItemTest::$shipmentItem protected property The shipment item.
ShipmentItemTest::setUp protected function Overrides UnitTestCase::setUp
ShipmentItemTest::testGetDeclaredValue public function @covers ::getDeclaredValue
ShipmentItemTest::testGetOrderItemId public function @covers ::getOrderItemId
ShipmentItemTest::testGetQuantity public function @covers ::getQuantity
ShipmentItemTest::testGetTariffCode public function @covers ::getTariffCode
ShipmentItemTest::testGetTitle public function @covers ::getTitle
ShipmentItemTest::testGetWeight public function @covers ::getWeight
ShipmentItemTest::testMissingProperties public function @covers ::__construct
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.