FakeBridge.php in Lightweight Directory Access Protocol (LDAP) 8.4
File
ldap_servers/tests/modules/ldap_servers_dummy/src/FakeBridge.php
View source
<?php
declare (strict_types=1);
namespace Drupal\ldap_servers_dummy;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\ldap_servers\Entity\Server;
use Drupal\ldap_servers\LdapBridgeInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Ldap\LdapInterface;
class FakeBridge implements LdapBridgeInterface {
protected $ldap;
protected $logger;
protected $entityManager;
protected $bindResult = TRUE;
public function __construct(LoggerInterface $logger, EntityTypeManagerInterface $entity_type_manager) {
$this->logger = $logger;
$this->entityManager = $entity_type_manager
->getStorage('ldap_server');
}
public function setServerById(string $sid) : void {
$server = $this->entityManager
->load($sid);
if ($server) {
$this
->setServer($server);
}
}
public function setServer(Server $server) : void {
if (!$this->ldap) {
$this->ldap = new FakeLdap();
}
}
public function bind() : bool {
$this->ldap
->bind();
return $this->bindResult;
}
public function setBindResult(bool $bindResult) : void {
$this->bindResult = $bindResult;
}
public function get() : LdapInterface {
return $this->ldap;
}
}
Classes
Name |
Description |
FakeBridge |
Fake LdapBridge to instantiate a fake server for testing. |