Permalink
Browse files

better error handling so tests dont bail out

git-svn-id: http://svn.php.net/repository/pear/packages/Net_LDAP/trunk@145016 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent ee08f54 commit 0290b76f1aca858cad46f265b6f65faf2b07a17f Jan Wagner committed Nov 28, 2003
Showing with 32 additions and 19 deletions.
  1. +32 −19 tests/PHPUnit/Net_LDAP.php
View
@@ -14,6 +14,9 @@ function setUp()
{
$this->config = $GLOBALS['ldap_config'];
$this->ldap = Net_LDAP::connect($this->config);
+ if (Net_LDAP::isError($this->ldap)) {
+ $this->fail($this->ldap->getMessage());
+ }
}
function testConnection()
@@ -66,13 +69,16 @@ function testSearch1()
$parms = array('scope' => 'base', 'attributes' => array('objectClass'));
$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();
- $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');
$this->assertTrue(is_array($oc), 'objectClass attribute value was no array');
}
@@ -82,31 +88,38 @@ function testSearch2()
$test = $GLOBALS['search2'];
$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)) {
- $this->assertTrue($result->count() >= 1, 'Empty Result set');
-
- $entry = $result->shiftEntry();
- $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');
+ $entry = $result->shiftEntry();
+ if (false === $entry) {
+ $this->fail('No entry could be fetched');
+ return false;
}
+
+ $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()
{
- 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;
}
- 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;
}
-
+
$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) {
$entry->dn($dn);

0 comments on commit 0290b76

Please sign in to comment.