Closed davidcoutadeur closed 8 months ago
A proposition of tests is done in #9
I use the FusionIAM OpenLDAP container for having a LDAP server: https://gitlab.ow2.org/fusioniam/fusioniam
TODO:
src/Ltb/Ldap.php
: connect, get_list, ldapSort, and sorted_searchsrc/Ltb/LtbUtil.php
: searchsrc/Ltb/Mail.php
: init_mailer, send_mail_global, and send_mailThis feature seems ready.
I have encountered two complications while writing the tests:
\Ltb\Ldap::ldapSort
method while testing \Ltb\LtbUtil::search
function. Indeed, the ldapSort method is sorting directly the array in its first argument, which is passed by reference, but somehow the mock is cloning the argument in the meantime. For the record, using Mockery::on
as described here: http://docs.mockery.io/en/latest/reference/pass_by_reference_behaviours.html is not working. (even the basic example provided is not working) Thus I took the decision to test the \Ltb\LtbUtil::search
method globally (including \Ltb\Ldap::connect
and \Ltb\Ldap::ldapSort
)Globally, I have covered all class and methods. Here is the result of the test coverage:
XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text --configuration phpunit.xml
PHPUnit 11.0.9 by Sebastian Bergmann and contributors.
Runtime: PHP 8.2.7 with Xdebug 3.2.0
Configuration: /home/davcou/Documents/ltb-ldap/phpunit.xml
............. 13 / 13 (100%)
Time: 00:00.163, Memory: 14.00 MB
OK (13 tests, 50 assertions)
Code Coverage Report:
2024-03-29 10:34:58
Summary:
Classes: 20.00% (1/5)
Methods: 20.83% (5/24)
Lines: 79.33% (142/179)
Ltb\AttributeValue
Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 18/ 18)
Ltb\Ldap
Methods: 25.00% ( 1/ 4) Lines: 79.37% ( 50/ 63)
Ltb\LtbUtil
Methods: 0.00% ( 0/ 1) Lines: 87.10% ( 27/ 31)
Ltb\Mail
Methods: 33.33% ( 1/ 3) Lines: 87.04% ( 47/ 54)
See github actions for test coverage. (.github/workflows/unittests.yml
)
The current unit tests are quite incomplete and not fully automated.
It is really difficult to mock php-ldap functions, so unit tests will require having a way to deploy a LDAP server.
I propose using phpunit as it seems to be the standard test framework for php projects.