phpcodeignitertestingphpunitcodeigniter-4

Error: Call to undefined function CodeIgniter\Test\helper() in PHPUnit tests for CodeIgniter project


I am working on a CodeIgniter project and have installed PHPUnit to run unit tests. However, when I execute the tests, I encounter the following error for each test, including the example tests provided by PHPUnit:

Error: Call to undefined function CodeIgniter\Test\helper()

Here is an example of the error message:

There was 1 error:

Error: Call to undefined function CodeIgniter\Test\helper()

C:\xampp\htdocs\moduloNoticias\vendor\codeigniter4\framework\system\Test\CIUnitTestCase.php:234

I have followed the standard installation procedure for PHPUnit in a CodeIgniter project. I have also ensured that PHPUnit is properly installed and configured.

What I have tried:

  1. Double-checked my composer.json and reinstalled dependencies using composer install.
  2. Verified that the helper function is defined and works correctly outside of the test environment.
  3. Checked the autoload configuration in app/Config/Autoload.php to ensure the helper is listed.
  4. Added the helpers as attributes in the CIUnitTestCase class and in my test class.
  5. Included the helpers in the PHPUnit XML configuration file (phpunit.xml.dist).

Is there any additional configuration I need to perform, or is there something I might be missing that could cause this error? Any guidance would be greatly appreciated.


Solution

  •     bootstrap="vendor/codeigniter4/framework/system/Test/bootstrap.php"
    

    change the boostrap path above in your "phpunit.xml.dist", the one located at the root of your project. That's what fixed my issue, for some reasons the healthTest.php does not work out of the box. in my case test that I wrote worked but I could never figure out why the healthiest was always failing.