You are here

class FakeBridge in Lightweight Directory Access Protocol (LDAP) 8.4

Fake LdapBridge to instantiate a fake server for testing.

Hierarchy

Expanded class hierarchy of FakeBridge

3 files declare their use of FakeBridge
GroupManagerTest.php in ldap_servers/tests/src/Kernel/GroupManagerTest.php
LdapEntryProvisionTest.php in ldap_user/tests/src/Kernel/LdapEntryProvisionTest.php
LoginTest.php in ldap_authentication/tests/src/Kernel/LoginTest.php

File

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

Namespace

Drupal\ldap_servers_dummy
View source
class FakeBridge implements LdapBridgeInterface {

  /**
   * LDAP.
   *
   * @var \Drupal\ldap_servers_dummy\FakeLdap
   */
  protected $ldap;

  /**
   * Logger.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * Entity Storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $entityManager;

  /**
   * Bind result.
   *
   * @var bool
   */
  protected $bindResult = TRUE;

  /**
   * Constructor.
   *
   * @param \Psr\Log\LoggerInterface $logger
   *   Logger.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity type manager.
   */
  public function __construct(LoggerInterface $logger, EntityTypeManagerInterface $entity_type_manager) {
    $this->logger = $logger;
    $this->entityManager = $entity_type_manager
      ->getStorage('ldap_server');
  }

  /**
   * {@inheritdoc}
   */
  public function setServerById(string $sid) : void {
    $server = $this->entityManager
      ->load($sid);

    /** @var \Drupal\ldap_servers\Entity\Server $server */
    if ($server) {
      $this
        ->setServer($server);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setServer(Server $server) : void {
    if (!$this->ldap) {
      $this->ldap = new FakeLdap();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function bind() : bool {
    $this->ldap
      ->bind();
    return $this->bindResult;
  }

  /**
   * Set bind result.
   *
   * @param bool $bindResult
   *   Result.
   */
  public function setBindResult(bool $bindResult) : void {
    $this->bindResult = $bindResult;
  }

  /**
   * {@inheritdoc}
   */
  public function get() : LdapInterface {
    return $this->ldap;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FakeBridge::$bindResult protected property Bind result.
FakeBridge::$entityManager protected property Entity Storage.
FakeBridge::$ldap protected property LDAP.
FakeBridge::$logger protected property Logger.
FakeBridge::bind public function Bind (authenticate) against an active LDAP database. Overrides LdapBridgeInterface::bind
FakeBridge::get public function Get LDAP service. Overrides LdapBridgeInterface::get
FakeBridge::setBindResult public function Set bind result.
FakeBridge::setServer public function Set Server. Overrides LdapBridgeInterface::setServer
FakeBridge::setServerById public function Set Server by ID. Overrides LdapBridgeInterface::setServerById
FakeBridge::__construct public function Constructor.