Skip to content

Commit

Permalink
better error handling so tests dont bail out
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/Net_LDAP/trunk@145016 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Jan Wagner committed Nov 28, 2003
1 parent ee08f54 commit 0290b76
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions tests/PHPUnit/Net_LDAP.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ function setUp()
{ {
$this->config = $GLOBALS['ldap_config']; $this->config = $GLOBALS['ldap_config'];
$this->ldap = Net_LDAP::connect($this->config); $this->ldap = Net_LDAP::connect($this->config);
if (Net_LDAP::isError($this->ldap)) {
$this->fail($this->ldap->getMessage());
}
} }


function testConnection() function testConnection()
Expand Down Expand Up @@ -66,13 +69,16 @@ function testSearch1()
$parms = array('scope' => 'base', 'attributes' => array('objectClass')); $parms = array('scope' => 'base', 'attributes' => array('objectClass'));


$result = $this->ldap->search($base, null, $parms); $result = $this->ldap->search($base, null, $parms);
$this->assertFalse(Net_Ldap::isError($result), 'Error searching for a specific entry'); if (Net_LDAP::isError($result)) {
$this->fail($result->getMessage());
return false;
}


$this->assertFalse( $result->count() == 0, 'Specified exisiting dn could not be found');

$entry = $result->shiftEntry(); $entry = $result->shiftEntry();
$this->assertEquals('net_ldap_entry', get_class($entry), 'Could not fetch specified entry'); if (false === $entry) {

$this->fail("Could not fetch entry $base");
return false;
}
$oc = $entry->get_value('objectClass'); $oc = $entry->get_value('objectClass');
$this->assertTrue(is_array($oc), 'objectClass attribute value was no array'); $this->assertTrue(is_array($oc), 'objectClass attribute value was no array');
} }
Expand All @@ -82,31 +88,38 @@ function testSearch2()
$test = $GLOBALS['search2']; $test = $GLOBALS['search2'];


$result = $this->ldap->search($test['base'], $test['filter'], $test['parms']); $result = $this->ldap->search($test['base'], $test['filter'], $test['parms']);
$this->assertFalse(Net_Ldap::isError($result), 'Search failed'); if (Net_LDAP::isError($result)) {
$this->fail($result->getMessage());
return false;
}


if(!Net_LDAP::isError($result)) { $entry = $result->shiftEntry();
$this->assertTrue($result->count() >= 1, 'Empty Result set'); if (false === $entry) {

$this->fail('No entry could be fetched');
$entry = $result->shiftEntry(); return false;
$this->assertTrue($entry, 'No entry could be fetched');

$attrs = array_keys($test['parms']['attributes']);
$value = $entry->get_value($attrs[0], 'single');
$this->assertTrue(is_string($value) && $value != '', 'Attribute value was not a string or empty');
} }

$attrs = array_keys($test['parms']['attributes']);
$value = $entry->get_value($attrs[0], 'single');
$this->assertTrue(is_string($value) && $value != '', 'Attribute value was not a string or empty');
} }


function testRename() function testRename()
{ {
if ($this->assertTrue(isset($GLOBALS['existing_dn']), 'exisiting dn not set in config')) { if (empty($GLOBALS['existing_dn'])) {
$this->fail('Exisiting dn not set in config');
return false; return false;
} }
if ($this->assertTrue(isset($GLOBALS['rename_dn']), 'rename dn not set in config')) { if (empty($GLOBALS['rename_dn'])) {
$this->fail('Rename dn not set in config');
return false; return false;
} }

$entry = $this->ldap->getEntry($GLOBALS['existing_dn']); $entry = $this->ldap->getEntry($GLOBALS['existing_dn']);
$this->assertEquals('net_ldap_entry', get_class($entry)); if (Net_LDAP::isError($entry) || $entry === false) {
$this->fail("Could not fetch entry {$GLOBALS['existing_dn']}");
return false;
}


foreach (array($GLOBALS['rename_dn'], $GLOBALS['existing_dn']) as $dn) { foreach (array($GLOBALS['rename_dn'], $GLOBALS['existing_dn']) as $dn) {
$entry->dn($dn); $entry->dn($dn);
Expand Down

0 comments on commit 0290b76

Please sign in to comment.