I have an API module in my application which is a RESTful API – basically set of public web services. I want to unit test my web services with PHPUnit. Now the problem…
Normally my app uses “dbname” database. But when unit testing with PHPUnit, I would like it to use “dbname_test” database (which contains the same set of tables, of course).
What is the best way to achieve this? In my PHPUnit test cases I am using Zend_Http_Client to send requests to my API module and then I am asserting the returned responses.
Thanks.
I would put a testing section in my application.ini:
Set an environment variable in my .htaccess:
And make sure I load the proper settings:
Another idea
Conditionally set the APPLICATION_ENV variable in .htaccess based on remote IP and user agent. If both do not match, then production is used.