MarkupInterfaceComparator.php

Same filename in other branches
  1. 9 core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php
  2. 10 core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php
  3. 11.x core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php

Namespace

Drupal\TestTools\Comparator

File

core/tests/Drupal/TestTools/Comparator/MarkupInterfaceComparator.php

View source
<?php

namespace Drupal\TestTools\Comparator;

use Drupal\Component\Render\MarkupInterface;
use SebastianBergmann\Comparator\Comparator;

/**
 * Compares MarkupInterface objects for equality.
 */
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);
    }

}

Classes

Title Deprecated Summary
MarkupInterfaceComparator Compares MarkupInterface objects for equality.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.