You are here

class HookStubProxy in Authenticated User Page Caching (Authcache) 7.2

(Internal) helper class representing a stub-hook.

Hierarchy

Expanded class hierarchy of HookStubProxy

File

tests/HookStub.inc, line 44
Defines some helper classes for stubbing and recording hook invocations.

View source
class HookStubProxy {
  protected $hookname;

  /**
   * Construct new stubbed hook.
   *
   * Note: Do not instantiate hook proxies directly but use StubModule::hook().
   *
   * @param string $hookname
   *   The fully qualified function name (including module prefix).
   */
  public function __construct($hookname) {
    $this->hookname = $hookname;
  }

  /**
   * Enable recording of invocations.
   *
   * @param any $return
   *   The result which should be returned when the hook is invoked.
   *
   * @return HookStubProxy
   *   A proxy object representing the stubbed hook.
   */
  public function on($return = NULL) {
    return HookStub::on($this->hookname, $return);
  }

  /**
   * Disable recording of invocations.
   *
   * @return HookStubProxy
   *   A proxy object representing the stubbed hook.
   */
  public function off() {
    return HookStub::off($this->hookname);
  }

  /**
   * Record one invocation.
   *
   * @return any
   *   A value specified by HookStubProxy::on().
   */
  public function record($args) {
    return HookStub::record($this->hookname, $args);
  }

  /**
   * Verify invocations.
   *
   * @param callable $checkfunc
   *   Use this function to test invocation expectations.
   * @param string $message
   *   A reference to a string for the validation message.
   *
   * @return bool
   *   Return TRUE when expectations are met, FALSE otherwise.
   */
  public function verify($checkfunc, &$message) {
    return HookStub::verify($this->hookname, $checkfunc, $message);
  }

  /**
   * Return the name of the stubbed function.
   *
   * @return string
   *   Fully qualified function this object represents.
   */
  public function hookname() {
    return $this->hookname;
  }

  /**
   * Return the recorded invocations.
   *
   * @return array
   *   An array of arrays. Each inner array representing the parameter list
   *   passed to one invocation.
   */
  public function invocations() {
    return HookStub::invocations($this->hookname);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HookStubProxy::$hookname protected property
HookStubProxy::hookname public function Return the name of the stubbed function.
HookStubProxy::invocations public function Return the recorded invocations.
HookStubProxy::off public function Disable recording of invocations.
HookStubProxy::on public function Enable recording of invocations.
HookStubProxy::record public function Record one invocation.
HookStubProxy::verify public function Verify invocations.
HookStubProxy::__construct public function Construct new stubbed hook.