<?php require_once 'vendor/autoload.php'; use Symfony\Component\Ldap\Ldap; use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter; $config = ['host' => 'localhost', 'port' => 389]; $dn = 'cn=admin,ou=admins,dc=openldap,dc=com'; $password = '******'; $adapter = new Adapter($config); $adapter->getConnection()->setOption('PROTOCOL_VERSION', 3); $ldap = new Ldap($adapter); $ldap->bind($dn, $password); $filter = 'objectClass=*'; $attributes = ['cn', 'sn', 'uid', 'description']; $query = $ldap->query($dn, 'objectClass=*', ['filter' => $attributes]); $collection = $query->execute(); var_dump('Good!', $collection->toArray());
public function testLdapBind() { $connection = $this->getMockBuilder(ConnectionInterface::class)->getMock(); $connection->expects($this->once())->method('bind')->with('foo', 'bar'); $this->adapter->expects($this->once())->method('getConnection')->will($this->returnValue($connection)); $this->ldap->bind('foo', 'bar'); }
/** * @BeforeScenario */ public function beforeScenario() { if ($this->bind_before_scenarion) { $this->client->bind($this->authentication['rdn'], $this->authentication['password']); } if ($this->purge_before_scenario) { } }