/** * @expectedException \Piwik\Exception\ErrorException * @expectedExceptionMessage triggered error */ public function test_connect_ThrowsPhpErrors() { $this->setPiwikErrorHandling(); $this->addLdapMethodThatTriggersPhpError('ldap_connect'); $ldapClient = new LdapClient(); $ldapClient->connect("hostname", 1234); }
private function makeLdapClient() { if (empty($this->ldapServers)) { // sanity check throw new Exception("No LDAP servers configured in LdapUsers instance."); } $ldapClientClass = $this->ldapClientClass; $this->ldapClient = is_string($ldapClientClass) ? new $ldapClientClass() : $ldapClientClass; foreach ($this->ldapServers as $server) { try { $this->ldapClient->connect($server->getServerHostname(), $server->getServerPort(), $this->getLdapNetworkTimeout()); $this->currentServerInfo = $server; $this->logger->info("LdapUsers::{function}: Using LDAP server {host}:{port}", array('function' => __FUNCTION__, 'host' => $server->getServerHostname(), 'port' => $server->getServerPort())); return; } catch (Exception $ex) { $this->logger->info("Model\\LdapUsers::{function}: Could not connect to LDAP server {host}:{port}: {message}", array('function' => __FUNCTION__, 'host' => $server->getServerHostname(), 'post' => $server->getServerPort(), 'message' => $ex->getMessage(), 'exception' => $ex)); } } $this->throwCouldNotConnectException(); }
private function makeLdapClient() { if (empty($this->ldapServers)) { // sanity check throw new Exception("No LDAP servers configured in LdapUsers instance."); } $ldapClientClass = $this->ldapClientClass; $this->ldapClient = is_string($ldapClientClass) ? new $ldapClientClass() : $ldapClientClass; foreach ($this->ldapServers as $server) { try { $this->ldapClient->connect($server->getServerHostname(), $server->getServerPort(), $this->getLdapNetworkTimeout()); $this->currentServerInfo = $server; Log::info("LdapUsers::%s: Using LDAP server %s:%s", __FUNCTION__, $server->getServerHostname(), $server->getServerPort()); return; } catch (Exception $ex) { Log::debug($ex); Log::info("Model\\LdapUsers::%s: Could not connect to LDAP server %s:%s: %s", __FUNCTION__, $server->getServerHostname(), $server->getServerPort(), $ex->getMessage()); } } $this->throwCouldNotConnectException(); }