public function AdjustmentTest::testArithmetic in Commerce Core 8.2
Tests the arithmetic operators.
@covers ::add @covers ::subtract @covers ::multiply @covers ::divide
File
- modules/
order/ tests/ src/ Kernel/ AdjustmentTest.php, line 157
Class
- AdjustmentTest
- @coversDefaultClass \Drupal\commerce_order\Adjustment @group commerce
Namespace
Drupal\Tests\commerce_order\KernelCode
public function testArithmetic() {
$first_adjustment = new Adjustment([
'type' => 'custom',
'amount' => new Price('2.00', 'USD'),
'label' => '10% off',
'percentage' => '0.1',
'source_id' => '1',
'included' => TRUE,
'locked' => TRUE,
]);
$second_adjustment = new Adjustment([
'type' => 'custom',
'amount' => new Price('3.00', 'USD'),
'label' => '10% off',
'percentage' => '0.1',
'source_id' => '1',
'included' => TRUE,
'locked' => TRUE,
]);
$third_adjustment = new Adjustment([
'type' => 'custom',
'amount' => new Price('5.00', 'USD'),
'label' => '10% off',
'percentage' => '0.1',
'source_id' => '1',
'included' => TRUE,
'locked' => TRUE,
]);
$fourth_adjustment = new Adjustment([
'type' => 'custom',
'amount' => new Price('6.00', 'USD'),
'label' => '10% off',
'percentage' => '0.1',
'source_id' => '1',
'included' => TRUE,
'locked' => TRUE,
]);
$this
->assertEquals($third_adjustment, $first_adjustment
->add($second_adjustment));
$this
->assertEquals($second_adjustment, $third_adjustment
->subtract($first_adjustment));
$this
->assertEquals($fourth_adjustment, $second_adjustment
->multiply('2'));
$this
->assertEquals($first_adjustment, $fourth_adjustment
->divide('3'));
}