You are here

class MarkupInterfaceComparator in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php \Drupal\TestTools\Comparator\MarkupInterfaceComparator
  2. 10 core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php \Drupal\TestTools\Comparator\MarkupInterfaceComparator

Compares MarkupInterface objects for equality.

Hierarchy

Expanded class hierarchy of MarkupInterfaceComparator

3 files declare their use of MarkupInterfaceComparator
BrowserTestBase.php in core/tests/Drupal/Tests/BrowserTestBase.php
KernelTestBase.php in core/tests/Drupal/KernelTests/KernelTestBase.php
MarkupInterfaceComparatorTest.php in core/tests/Drupal/KernelTests/Core/Test/Comparator/MarkupInterfaceComparatorTest.php

File

core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php, line 11

Namespace

Drupal\TestTools\Comparator
View source
class MarkupInterfaceComparator extends Comparator {

  /**
   * {@inheritdoc}
   */
  public function accepts($expected, $actual) {

    // If at least one argument is a MarkupInterface object, we take over and
    // convert to strings before comparing.
    return $expected instanceof MarkupInterface && $actual instanceof MarkupInterface || $expected instanceof MarkupInterface && is_scalar($actual) || is_scalar($expected) && $actual instanceof MarkupInterface;
  }

  /**
   * {@inheritdoc}
   */
  public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = FALSE, $ignoreCase = FALSE) {
    $expected_safe = (string) $expected;
    $actual_safe = (string) $actual;
    $comparator = $this->factory
      ->getComparatorFor($expected_safe, $actual_safe);
    $comparator
      ->assertEquals($expected_safe, $actual_safe, $delta, $canonicalize, $ignoreCase);
  }

}

Members

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