From 5628e48d09bf873e8eb657d85838b1f19973b807 Mon Sep 17 00:00:00 2001 From: David Coutadeur Date: Fri, 29 Mar 2024 11:25:29 +0100 Subject: [PATCH] improve unit test coverage (#8) --- tests/Ltb/AttributeValueTest.php | 45 +++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/tests/Ltb/AttributeValueTest.php b/tests/Ltb/AttributeValueTest.php index ef695d8..c2b0209 100644 --- a/tests/Ltb/AttributeValueTest.php +++ b/tests/Ltb/AttributeValueTest.php @@ -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 { @@ -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'], @@ -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('test1@domain.com', $mail, "not getting test1@domain.com 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:test1@domain.com', + 1 => 'smtp:test2@domain.com' + ] + ]); + + # Test ldap_get_mail_for_notification + $mail = Ltb\AttributeValue::ldap_get_mail_for_notification(null, null); + $this->assertEquals('test1@domain.com', $mail, "not getting test1@domain.com as proxyAddress for notification"); + } + }