Skip to content

Commit

Permalink
improve unit test coverage (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Mar 29, 2024
1 parent 649ba2b commit 5628e48
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions tests/Ltb/AttributeValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
require __DIR__ . '/../../vendor/autoload.php';
use PHPUnit\Framework\TestCase;

// global variable for ldap_get_mail_for_notification function
$GLOBALS['mail_attributes'] = array("mail");

final class AttributeValueTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
{

Expand All @@ -29,9 +26,28 @@ public function test_ldap_get_first_available_value(): void

}

public function test_ldap_get_first_available_value_empty(): void
{

$phpLDAPMock = Mockery::mock('overload:Ltb\PhpLDAP');
$phpLDAPMock->shouldreceive([
'ldap_get_attributes' => ['cn'],
'ldap_get_values' => [
'count' => 0
]
]);

$ent = Ltb\AttributeValue::ldap_get_first_available_value(null, null, ['cn']);
$this->assertFalse($ent, "not getting false result whereas no value has been returned");

}

public function test_ldap_get_mail_for_notification(): void
{

// global variable for ldap_get_mail_for_notification function
$GLOBALS['mail_attributes'] = array("mail");

$phpLDAPMock = Mockery::mock('overload:Ltb\PhpLDAP');
$phpLDAPMock->shouldreceive([
'ldap_get_attributes' => ['mail'],
Expand All @@ -42,9 +58,30 @@ public function test_ldap_get_mail_for_notification(): void
]
]);

# Test ldap_get_first_available_value
# Test ldap_get_mail_for_notification
$mail = Ltb\AttributeValue::ldap_get_mail_for_notification(null, null);
$this->assertEquals('[email protected]', $mail, "not getting [email protected] as mail for notification");
}

public function test_ldap_get_proxy_for_notification(): void
{

// global variable for ldap_get_mail_for_notification function
$GLOBALS['mail_attributes'] = array("proxyAddresses");

$phpLDAPMock = Mockery::mock('overload:Ltb\PhpLDAP');
$phpLDAPMock->shouldreceive([
'ldap_get_attributes' => ['proxyAddresses'],
'ldap_get_values' => [
'count' => 2,
0 => 'smtp:[email protected]',
1 => 'smtp:[email protected]'
]
]);

# Test ldap_get_mail_for_notification
$mail = Ltb\AttributeValue::ldap_get_mail_for_notification(null, null);
$this->assertEquals('[email protected]', $mail, "not getting [email protected] as proxyAddress for notification");
}

}

0 comments on commit 5628e48

Please sign in to comment.