You are here

class PackageTypeTest in Commerce Shipping 8.2

Same name in this branch
  1. 8.2 tests/src/Functional/PackageTypeTest.php \Drupal\Tests\commerce_shipping\Functional\PackageTypeTest
  2. 8.2 tests/src/Unit/Plugin/Commerce/PackageType/PackageTypeTest.php \Drupal\Tests\commerce_shipping\Unit\Plugin\Commerce\PackageType\PackageTypeTest

@coversDefaultClass \Drupal\commerce_shipping\Plugin\Commerce\PackageType\PackageType @group commerce_shipping

Hierarchy

Expanded class hierarchy of PackageTypeTest

File

tests/src/Unit/Plugin/Commerce/PackageType/PackageTypeTest.php, line 14

Namespace

Drupal\Tests\commerce_shipping\Unit\Plugin\Commerce\PackageType
View source
class PackageTypeTest extends UnitTestCase {

  /**
   * The test package type.
   *
   * @var \Drupal\commerce_shipping\Plugin\Commerce\PackageType\PackageType
   */
  protected $packageType;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $plugin_definition = [
      'id' => 'test id',
      'remote_id' => 'test remote id',
      'label' => 'test label',
      'dimensions' => [
        'length' => '1',
        'width' => '2',
        'height' => '3',
        'unit' => 'mm',
      ],
      'weight' => [
        'number' => '4',
        'unit' => 'kg',
      ],
    ];
    $this->packageType = new PackageType([], 'test', $plugin_definition);
  }

  /**
   * @covers ::getId
   */
  public function testGetId() {
    $this
      ->assertEquals('test id', $this->packageType
      ->getId());
  }

  /**
   * @covers ::getRemoteId
   */
  public function testGetRemoteId() {
    $this
      ->assertEquals('test remote id', $this->packageType
      ->getRemoteId());
  }

  /**
   * @covers ::getLabel
   */
  public function testGetLabel() {
    $this
      ->assertEquals('test label', $this->packageType
      ->getLabel());
  }

  /**
   * @covers ::getLength
   * @covers ::getWidth
   * @covers ::getHeight
   */
  public function testGetDimensions() {
    $this
      ->assertEquals(new Length('1', 'mm'), $this->packageType
      ->getLength());
    $this
      ->assertEquals(new Length('2', 'mm'), $this->packageType
      ->getWidth());
    $this
      ->assertEquals(new Length('3', 'mm'), $this->packageType
      ->getHeight());
  }

  /**
   * @covers ::getWeight
   */
  public function testGetWeight() {
    $this
      ->assertEquals(new Weight('4', 'kg'), $this->packageType
      ->getWeight());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PackageTypeTest::$packageType protected property The test package type.
PackageTypeTest::setUp protected function Overrides UnitTestCase::setUp
PackageTypeTest::testGetDimensions public function @covers ::getLength @covers ::getWidth @covers ::getHeight
PackageTypeTest::testGetId public function @covers ::getId
PackageTypeTest::testGetLabel public function @covers ::getLabel
PackageTypeTest::testGetRemoteId public function @covers ::getRemoteId
PackageTypeTest::testGetWeight public function @covers ::getWeight
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.
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.