2

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.

1
  • Post your code. Commented May 23, 2024 at 4:07

1 Answer 1

3
    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 healthtest was always failing.

Sign up to request clarification or add additional context in comments.

2 Comments

That solved my issue! However, it seems that PHPUnit in CodeIgniter has some other problems, but at least it's working for now. Thank you very much!
You are very welcome,what other problems are you having? I am willing to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.