ltb-project / ltb-common

PHP framework for LTB project applications
https://packagist.org/packages/ltb-project/ldap
GNU General Public License v3.0
3 stars 2 forks source link

Create unit tests for existing functions #8

Closed davidcoutadeur closed 8 months ago

davidcoutadeur commented 8 months ago

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.

davidcoutadeur commented 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:

davidcoutadeur commented 8 months ago

This feature seems ready.

I have encountered two complications while writing the tests:

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)