I am trying TDD in Codeigniter and I’m stuck. I am using TOAST and want to test a simple feature without touching the database…
function test_get_products_by_user_id()
{
}
How to create a mock of the database for a case like this? I do not want to query the database for such tests.
Even though I wanted to avoid querying a real database, the answer for this is to create a separate database and fill it with dummy data for testing. You can easily switch the database when running the tests – this is written in the documentation
“The reason we use a multi-dimensional array rather than a more simple one is to permit you to optionally store multiple sets of connection values. If, for example, you run multiple environments (development, production, test, etc.) under a single installation, you can set up a connection group for each, then switch between groups as needed. For example, to set up a “test” environment you would do this:”