You are here

class FakeLdap in Lightweight Directory Access Protocol (LDAP) 8.4

Fake server to simulate querying with symfony/ldap.

Can be used in tests, requires overloading the LdapBridge class.

Hierarchy

  • class \Drupal\ldap_servers_dummy\FakeLdap implements \Symfony\Component\Ldap\LdapInterface

Expanded class hierarchy of FakeLdap

File

ldap_servers/tests/modules/ldap_servers_dummy/src/FakeLdap.php, line 16

Namespace

Drupal\ldap_servers_dummy
View source
class FakeLdap implements LdapInterface {

  /**
   * Let binding fail.
   *
   * @var bool
   */
  protected $bindException = FALSE;

  /**
   * List of query responses keyed by query.
   *
   * @var array
   */
  protected $queryResult;

  /**
   * Escape response.
   *
   * @var string
   */
  protected $escapeResponse;

  /**
   * Entry Manager.
   *
   * @var \Symfony\Component\Ldap\Adapter\EntryManagerInterface
   */
  protected $entryManagerResponse;

  /**
   * {@inheritdoc}
   */
  public function bind(string $dn = NULL, string $password = NULL) : void {
    if ($this->bindException) {
      throw new ConnectionException('Failed connection');
    }
  }

  /**
   * {@inheritdoc}
   */
  public function query($dn, $query, array $options = []) {
    $response = new FakeQuery();
    $response
      ->setResult($this->queryResult[$query] ?? new FakeCollection([]));
    return $response;
  }

  /**
   * {@inheritdoc}
   */
  public function getEntryManager() : EntryManagerInterface {
    return $this->entryManagerResponse;
  }

  /**
   * {@inheritdoc}
   */
  public function escape($subject, $ignore = '', $flags = 0) : string {
    return $this->escapeResponse;
  }

  /**
   * Set bind exception.
   *
   * @param bool $bindException
   *   Bind exception.
   */
  public function setBindException(bool $bindException) : void {
    $this->bindException = $bindException;
  }

  /**
   * Set the query result.
   *
   * @param array $queryResult
   *   Query result.
   */
  public function setQueryResult(array $queryResult) : void {
    $this->queryResult = $queryResult;
  }

  /**
   * Set the escape response.
   *
   * @param string $escapeResponse
   *   Response.
   */
  public function setEscapeResponse(string $escapeResponse) : void {
    $this->escapeResponse = $escapeResponse;
  }

  /**
   * Set the entry manager response.
   *
   * @param \Symfony\Component\Ldap\Adapter\EntryManagerInterface $entryManagerResponse
   *   Entry Manager.
   */
  public function setEntryManagerResponse(EntryManagerInterface $entryManagerResponse) : void {
    $this->entryManagerResponse = $entryManagerResponse;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FakeLdap::$bindException protected property Let binding fail.
FakeLdap::$entryManagerResponse protected property Entry Manager.
FakeLdap::$escapeResponse protected property Escape response.
FakeLdap::$queryResult protected property List of query responses keyed by query.
FakeLdap::bind public function
FakeLdap::escape public function
FakeLdap::getEntryManager public function
FakeLdap::query public function
FakeLdap::setBindException public function Set bind exception.
FakeLdap::setEntryManagerResponse public function Set the entry manager response.
FakeLdap::setEscapeResponse public function Set the escape response.
FakeLdap::setQueryResult public function Set the query result.