You are here

class PriceComparator in Commerce Core 8.2

Provides a PHPUnit comparator for prices.

Hierarchy

  • class \Drupal\commerce_price\Comparator\PriceComparator extends \SebastianBergmann\Comparator\Comparator

Expanded class hierarchy of PriceComparator

3 files declare their use of PriceComparator
CommerceBrowserTestBase.php in tests/src/Functional/CommerceBrowserTestBase.php
CommerceKernelTestBase.php in tests/src/Kernel/CommerceKernelTestBase.php
CommerceWebDriverTestBase.php in tests/src/FunctionalJavascript/CommerceWebDriverTestBase.php

File

modules/price/src/Comparator/PriceComparator.php, line 12

Namespace

Drupal\commerce_price\Comparator
View source
class PriceComparator extends Comparator {

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

  /**
   * {@inheritdoc}
   */
  public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = FALSE, $ignoreCase = FALSE) {
    assert($expected instanceof Price);
    assert($actual instanceof Price);
    if (!$actual
      ->equals($expected)) {
      throw new ComparisonFailure($expected, $actual, (string) $expected, (string) $actual, FALSE, sprintf('Failed asserting that Price %s matches expected %s.', $actual, $expected));
    }
  }

}

Members

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