# FIX get_string_between
Noticed that the typing of the arguments was incorrect and then found
the implementation suspicious. The implemented test confirmed that it
was flawed. Fixed.
Apparently this method is used in get_next_value .
# Qual: Exclude some tests from windows-ci until fixed
Until #28598 and #28264 find some way to the develop branch, this update will
skip the tests that currently fail on windows so that the results of other
tests have an effect on the CI status and github annotations
# Fix: Ob buffer cleanup on exception
The OB buffer capture was incorrectly cleaned up on exception.
This fixes that.
Also modified the SecurityTest to enable running it standalone
# Fix: Correctly close active output buffer.
Use ob_get_clean(), not ob_get_contents() and ob_clean().
Tests were failing with:
FunctionsLibTest::testVerifCond with data set "Test that verifConf("0") returns false" ('0', false)
Test code or tested code did not (only) close its own output buffers
OK, but incomplete, skipped, or risky tests\!
Also refactored a test case to use a data provider which helped identify that it was related
to dol_eval.
# Fix: Script tests (on Windows)
- Set `exit(255)` instead of `exit(-1)` in `scripts/bank/export-bank-receipts.php`.
On *nix, the -1 converts into an exist code of 255 but on windows it
is -1, making the test fail.
- Add a helper method to execute php scripts using the php binary used
to run phpunit.
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
# Qual: FactureTest - use assertions rather than dying in the setup.
The 'die()' instructions have been replaced - not all tests should fail
because the preconditions for a test case are not met.
# Fix: Skip UtilsTest on windows where ls is not available
The test in question uses 'ls' which is not available on windows.
This change limits the execution to non windows systems.
# Fix: Use accessible temporarypath for CMailFileTest
'/tmp' does not exist on all systems and is subject to open_basedir
restrictions. Selected another temporary path for the test.
* Fix: Use accessible path for CategorieTest
# Fix: Use accessible path for CategorieTest
The test was using '/' (root of the filesystem) which was outside
the open_basedir paths. Modified the path to the medias directory to allow the test to pass with open_basedir restriction in effect.
* Update CategorieTest.php
---------
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
# Qual: Improve logging on phpunit error by limiting to new log lines
Log only the new files since the start of the failed test within the limit
of the number of requested lines.
To do this, the log file size is recorded in setUp() to show only the data
beyond this limit on error.
# Qual: Improve PhpUnit logging in case of error.
- Log exception message with extra log information.
- Do not output markers for dolibarr.log if no log lines should be shown.
- Use GitHub action style prefixes to group messages
# Fix: phpunit - Add adapter to "not existing directory" assertion
This is a helper function added to the common test class which is useful
to maintain cross phpunit version compatibility without triggering a
deprecation error for internal phpunit test functions.
Used in a testcase for dol_dir_move in a pending PR
* Fix: Replace deprecated module names in code strings
# Fix: Replace deprecated module names in code strings
A few cases that slipped through the manual replacements
* Qual: Enable deprecation notices in CodingPhpTest for isModEnabled
# Qual: Enable deprecation notices in CodingPhpTest for isModEnabled
As all detections are now fixed, we can enable the deprecation notice
trigger in the CodingPhpTest.
* Fix: Fix var_dump checker
# Fix: Fix var_dump checker
The core issue was that in PHP whitespace includes newlines by default, the m modifier
is needed to not match multilines.
* Fix: Allow multiple var_dumps on single comment line, refactor
# Fix: Allow multiple var_dumps on single comment line, refactor
Updated the regex to not match a var_dump preceeded with a comment
somewhere on the line.
Refactored var_dump check in dedicated method.
* Qual: Test the test function !
# Qual: Test the test function !
Test that the test function detecting var_dump does detect them.
* Qual: CodingPhpTest - remove comments from file before checking
# Qual: CodingPhpTest - remove comments from file before checking
This helps remove false positives and may have a positive impact on performance.
---------
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
* Qual: CommonClassTest - less verbosity, but better when error
# Qual: CommonClassTest - less verbosity, but better when error
- Report the test method and parameters in case of error.
- Less verbosity about setup.
- $_ENV was empty array, replaced with getenv()
* Qual: Refactor CodingPhpTest
# Qual: Refactor CodingPhpTest
- Use dataprovider (better progress report, better errors, better continuation)
- Use dol_dir_list's exclude_filter capability (do not traverse the excluded dirs)
- Reduce debug output from dolibarr.log (not really relevant for these tests).
* Fix: References to loop variables outside loop
# Fix: References to loop variables outside loop
The test referenced some undefined variables outside foreach loops ($val[0])
* Update CommonClassTest.class.php
---------
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
* Fix: Correct CommonClassTest's constructor
# Fix: Correct CommonClassTest's constructor
Dataproviders did not work because of the issue with the constructor
* Qual: Refactor module name list, add mapping to class name
# Qual: Refactor module name list, add mapping to class name
Based on ModuleTest and search for modules in the code, complete the
list of modules and map to the class names.
This will allow reuse in the ModuleTest.
* Qual: Refactor ModulesInit test
# Qual: Refactor ModulesInit test
Use the updated common module mapping list, more complete than
the original list.
Also refactor the test to use a data provider.
* Fix: valid module test must now use array_key_exists
# Fix: valid module test must now use array_key_exists
Because of the introduction of null key values, isset on the array no
longer works, using array_key_exists to test if the modulename is valid.
* fixup! Qual: Refactor module name list, add mapping to class name
* Qual: Less verbosity for tests
# Qual: Less verbosity for tests
The verbosity on setup/teardown/... is not really usefull and
makes the log less readable. Reducing the verbosity while allowing
to set an environment variable PHPUNIT_DEBUG to enable it.
* Qual: Add test to validate module_names
# Qual: Add test to validate module_names
This ensures that all explitly tested module names appear in the reference list.
Displays messages when the module_name is deprecated
* Update CodingPhpTest.php
* Update CodingPhpTest.php
---------
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
* Fix: Workaround for false security issue in tests
# Fix: Workaround for false security issue in tests
This is a quick workaround for the false security issues in tests
by setting the ['SELF'] variable to something that is
considered harmless
* Update windows-ci workflow
# Update windows-ci workflow
- Setup_conf.sh - Added caching feature;
- phpunit.bat - Example updated based on experience with php web server
- Provide dolibarr.log and phpunit output as artefacts.
- Convert PHPUNIT log to Github Annotations
- Setup php web server for API tests
- Enable caching sql initialisation
* Qual: Re-enable open_basedir restriction in tests
# Qual: Re-enable open_basedir restriction in tests
Using open_basedir restriction is closer to the production reality
and seemed to generate some issues on a windows development machine.
---------
Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>