I’m writing a library for CodeIgniter, and when writing tests, I need to check what happens when the library’s or CodeIgniter’s configuration is changed to various options I am making available.
The simplest way out appears to be using the Config class to get and set config variables on the fly, and it does solve the problem. I just don’t like the look of that solution.
What are the equivalents to this in other languages/frameworks, what are the potential problems that might be faced, and how to avoid all this altogether?
I dont know what your testing but I know that when I test (and this has been the policy of most places I’ve worked, well the ones that have their stuff together) I try to make sure all of my input is controlled and validated, as in I know exactly what is going and what should come out.
So for your specific case, if possible I would generate a “Testing” config file and use that so that you know for sure exactly what is going and what should be coming out.
EDIT: To answer your question more specifically, in my opinion I would say it is not okay to change configuration values on the fly.
Why? Because what if something breaks and you don’t catch it and suddenly your configuration values are changed and get deployed to production and…BOOM meltdown. Obviously a worse case scenario but still