codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: Uncaught Error: Undefined constant Config\SUPPORTPATH #7399

Closed adalyana closed 1 year ago

adalyana commented 1 year ago

PHP Version

8.1

CodeIgniter4 Version

4.3.1

CodeIgniter4 Installation Method

Composer (using Manual (zip or tar.gz))

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

mysql 5.6

What happened?

We have our proyect runing in google cloud run, however when set the enviroment to testing we get this error.

Uncaught Error: Undefined constant "CodeIgniter\Config\SUPPORTPATH" in /var/www/html/system/Config/AutoloadConfig.php:144

Steps to Reproduce

Set CI_ENVIRONMENT to testing, run any request/cli and wil see the error.

It only happens in "real" environment but y can try in the local development using docker or wherever you want.

In AutoloadConfig.php before the if (isset($_SERVER['CI_ENVIRONMENT']) && $_SERVER['CI_ENVIRONMENT'] === 'testing') { } try dump SUPPORTPATH. I don't know why it happens because if you check bootstrap.php the line: defined('SUPPORTPATH') || define('SUPPORTPATH', realpath(TESTPATH . '_support/') . DIRECTORY_SEPARATOR); and dump this part "realpath(TESTPATH . '_support/') " you wont get the error, the error is the constant itself.

Expected Output

No errors.

Anything else?

I found this thread but is old: https://forum.codeigniter.com/thread-73489.html

The tests folder and _support foder are in the main project, in the same level that app folder

kenjis commented 1 year ago

You cannot use testing. Please use another environment value like that Forum post.

The environment testing is the special one for PHPUnit testing. It has special conditions built into the framework at various places to assist with that. You can’t use it for your development. https://codeigniter4.github.io/CodeIgniter4/general/environments.html#the-environment-constant

adalyana commented 1 year ago

I would like to understand why I cannot use it. I want to run tests before deploy but I receive that error

kenjis commented 1 year ago

testing is reserved for PHPUnit testing. If you use it, the framework will change the behavior for PHPUnit testing.

You can add another environment value like test. Create a test.php file (copy production.php or development.php) in app/Config/Boot and set CI_ENVIRONMENT to test

adalyana commented 1 year ago

Got it, I can create my own environment, it works for our implementation in the project. Thanks