You are here

public function PriceTest::testArithmetic in Commerce Core 8.2

Tests the arithmetic methods.

::covers add ::covers subtract ::covers multiply ::covers divide.

File

modules/price/tests/src/Unit/PriceTest.php, line 122

Class

PriceTest
Tests the Price class.

Namespace

Drupal\Tests\commerce_price\Unit

Code

public function testArithmetic() {
  $result = $this->price
    ->add(new Price('5', 'USD'));
  $this
    ->assertEquals(new Price('15', 'USD'), $result);
  $result = $this->price
    ->subtract(new Price('5', 'USD'));
  $this
    ->assertEquals(new Price('5', 'USD'), $result);
  $result = $this->price
    ->multiply('5');
  $this
    ->assertEquals(new Price('50', 'USD'), $result);
  $result = $this->price
    ->divide('10');
  $this
    ->assertEquals(new Price('1', 'USD'), $result);
}