kenjis/ci-phpunit-test

System and configuration files location issue

qaribhaider opened this issue · 6 comments

After setting PHPUnit using the guides here on an existing CodeIgniter 3 project, I kept on getting various errors.

Here are the issues which occurred and what were the workarounds I opted for; I believe these should be fixed in future versions

Can't find "system" folder.
We have changed the system folder name in our CodeIgniter project, and there is no way to pass that folder name as an argument while setting up the project. Had to comment out the code within Installer.php and change the system folder name in tests/Bootstrap.php later

Your system/application folder path does not appear to be set correctly
Even though I installed using custom arguments, the folder locations under Bootstrap.php were not changed. Had to manually change that later

Call to undefined function get_instance()
After a lot of digging found out that this is due to the missing config.php file, under the CodeIgniter config folder. The script I believe only looks directly under config/ folder, however, for CI the files can be under config/development or config/production, etc. This should be a configuration option.

Why do you want to change the system folder name?
It is not common practice, so ci-phpunit-test the installer (install.php) does not support it.

Even though I installed using custom arguments, the folder locations under Bootstrap.php were not changed. Had to manually change that later

I don't know what do you want. Could you send PR?

Call to undefined function get_instance()

Is it the issue on ci-phpunit-test? I don't get the issue.
How to reproduce?

Mate, I have already worked around these, but someone else might face similar issues, hence opened this thread as suggestions which you might choose to implement in your next release. But would suggest some research from your end as well before you comment.

Can't find "system" folder.
This might not be a common practice for you, but that does not mean it is not supported by the framework. Please read the documentation here: https://www.codeigniter.com/userguide3/installation/index.html

It clearly mentions "If you wish to increase security by hiding the location of your CodeIgniter files you can rename the system and application folders to something more private". I have chosen this as a practice for my CI apps, hence suggested adding an argument upon installation to add a custom system folder name, similar to the one you have for the applications folder.

Your system/application folder path does not appear to be set correctly
In your install instructions, php vendor/kenjis/ci-phpunit-test/install.php -a <application_dir> -p <public_dir> -t <unittest_dir>, there are clearly mentioned arguments for application directory, even though I specified this during the install, this had to be manually changed later under Bootstrap.php, what I have suggested is to do this automatically, so the user does not have to change it manually

Call to undefined function get_instance()
For CodeIgniter, the config.php file is usually present under "[Application root]/[Applications folder]/config/". But you can customize it to store separate versions for different environments. Hence you can place separate config.php files under "[Application root]/[Applications folder]/config/production/" and "[Application root]/[Applications folder]/config/development/". You can read more about this here: https://codeigniter.com/userguide3/libraries/config.html#environments

The phpunit test here does not cater to this, and if the config.php file is not present under "[Application root]/[Applications folder]/config/" then it throws this error.

Hope the above will give you better clarity of the challenges faced. Let me know if you need further details please.

At last, as I have mentioned earlier, these are suggestions which you can choose to implement or not, but I have mainly opened this thread as someone else might face similar issues, and will spend time in finding a solution, so this can serve as a guide for them.

Cheers!

@qaribhaider I got your intention. Thank you for reporting!

It clearly mentions "If you wish to increase security by hiding the location of your CodeIgniter files you can rename the system and application folders to something more private". I have chosen this as a practice for my CI apps, hence suggested adding an argument upon installation to add a custom system folder name, similar to the one you have for the applications folder.

I don't agree with the opinion of the CI3 docs, but it is true that CI3 officially support the change.
So I wrote "ci-phpunit-test does not support it", but it was wrong. To be precise, install.php does not support it.
You can fix the path in the Bootstrap.php and it works fine.

The phpunit test here does not cater to this, and if the config.php file is not present under "[Application root]/[Applications folder]/config/" then it throws this error.

I have no intention to have altered the behavior of CI Config class.
But during the test execution, the environment is always set to testing.
If you don't have config/config.php nor config/testing/config.php, there is no config.php found.
So it may cause an error.

Thanks @kenjis those last two lines of your last comment were exactly what I was looking for.

I just did: cp -r application/config/development/ application/config/testing and voila! Problem solved.