You are here

class TermMergerSpy in Term Merge 8

A term merge test class that keeps a list of called functions.

Hierarchy

Expanded class hierarchy of TermMergerSpy

1 file declares its use of TermMergerSpy
MergeTermsConfirmTest.php in tests/src/Kernel/Form/MergeTermsConfirmTest.php

File

tests/src/Kernel/TestDoubles/TermMergerSpy.php, line 10

Namespace

Drupal\Tests\term_merge\Kernel\TestDoubles
View source
class TermMergerSpy extends TermMergerMock {
  private $functionCalls = [];

  /**
   * {@inheritdoc}
   */
  public function mergeIntoNewTerm(array $termsToMerge, $newTermLabel) {
    $this->functionCalls[__FUNCTION__] = [
      $termsToMerge,
      $newTermLabel,
    ];
    return parent::mergeIntoNewTerm($termsToMerge, $newTermLabel);
  }

  /**
   * {@inheritdoc}
   */
  public function mergeIntoTerm(array $termsToMerge, TermInterface $targetTerm) {
    $this->functionCalls[__FUNCTION__] = [
      $termsToMerge,
      $targetTerm,
    ];
    parent::mergeIntoTerm($termsToMerge, $targetTerm);
  }

  /**
   * Checks a function was called on the object.
   */
  public function assertFunctionCalled($function) {
    if (!isset($this->functionCalls[$function])) {
      throw new \Exception("{$function} was not called");
    }
  }

  /**
   * Returns an array of called function names.
   *
   * @return string[]
   *   An array of called function names.
   */
  public function calledFunctions() {
    return array_keys($this->functionCalls);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TermMergerSpy::$functionCalls private property
TermMergerSpy::assertFunctionCalled public function Checks a function was called on the object.
TermMergerSpy::calledFunctions public function Returns an array of called function names.
TermMergerSpy::mergeIntoNewTerm public function Merges two or more terms into a new term. Overrides TermMergerMock::mergeIntoNewTerm
TermMergerSpy::mergeIntoTerm public function Merges one or more terms into an existing term. Overrides TermMergerDummy::mergeIntoTerm