You are here

class AdjustmentComparator in Commerce Core 8.2

Provides a PHPUnit comparator for adjustments.

Hierarchy

  • class \Drupal\commerce_order\Comparator\AdjustmentComparator extends \SebastianBergmann\Comparator\Comparator

Expanded class hierarchy of AdjustmentComparator

1 file declares its use of AdjustmentComparator
OrderKernelTestBase.php in modules/order/tests/src/Kernel/OrderKernelTestBase.php

File

modules/order/src/Comparator/AdjustmentComparator.php, line 12

Namespace

Drupal\commerce_order\Comparator
View source
class AdjustmentComparator extends Comparator {

  /**
   * {@inheritdoc}
   */
  public function accepts($expected, $actual) {
    return $expected instanceof Adjustment && $actual instanceof Adjustment;
  }

  /**
   * {@inheritdoc}
   */
  public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = FALSE, $ignoreCase = FALSE) {
    assert($expected instanceof Adjustment);
    assert($actual instanceof Adjustment);
    $expected_array = $expected
      ->toArray();
    $actual_array = $actual
      ->toArray();
    unset($expected_array['amount'], $actual_array['amount']);
    if (!$actual
      ->getAmount()
      ->equals($expected
      ->getAmount()) || $expected_array !== $actual_array) {
      throw new ComparisonFailure($expected, $actual, var_export($expected, TRUE), var_export($actual, TRUE), FALSE, sprintf('Failed asserting that Adjustment "%s" matches expected "%s".', $actual
        ->getLabel(), $expected
        ->getLabel()));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdjustmentComparator::accepts public function Returns whether the comparator can compare two values.
AdjustmentComparator::assertEquals public function Asserts that two values are equal.