I'm writing a PHP application, following test driven development principles.
I want two different configurations: one for development, and one for production.
I will be continually expanding the application's features, so one problem is I don't want the production credentials/configuration to be overwritten each time I upload an upgrade. This is just one heuristic. And it could be done 100 different ways. I can't see the wood for the trees, I need help!
Example 1: the application interracts with Ebay's API. For the application to authenticate itself with Ebay, it needs to submit authentication keys. But I'll need two sets of keys: one for development in Ebay's sandbox, and another for production. Eventually these will be stored a database or similar, since they expire and need renewing, but pretend that's not the case - assume they are static.
Example 2: Database host, name and credentials which would be different in testing and production
I'm having trouble articulating my question. In short, want to follow TDD best practice.
My instinct would be to have a configuration file which is read by some class. That gives two options:
- Either there would be two files, one for tests and one for production, or
- just one config file, who's contents would be altered for production.
But say we choose option 1, we're back to square one, because somewhere there needs to be a setting saying whether this the test or production environment.
And say we choose option 2, the file's location would still need(?) to be hard coded somewhere.
And then there's the scenario where objects need to be swapped depending on whether it's production or development. AFAIK the factory pattern solves this, but again, somewhere, the code needs to be told what environment we're in, and/or which of the two classes to use.
In books I've read, the principle I think is to treat the application as an onion, feeding in configuration information to the application so the whole application is context-independent. So for a command-line tool, configuration could be given by command line arguments. But how might this be done for a Java Swing application, or a PHP web app?