I have created a testing database environment as follows:
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
),
)
);
When I initialise my database in my setUp function this all appears to work fine:
Mail::pretend(true);
Artisan::call('migrate');
$this->seed();
Any query directly in my test directly in my test class returns what I would expect however if I call a function on my model that does anything with the database it uses my 'live' (I'm running this in a vagrant dev server so no risk of ruining anything) database instead of my test one. Do I need to change my configuration further to ensure it is using my test database? Or do I need to instantiate my model in a special way?
An example of what doesn't work. In my test:
// gets the correct company
$comp = Companies::find(1);
// gets results from wrong database
$comp->quotesAndOrders();
where quotesAndOrders does a simple query on a hasMany relationship (orders)
$this->orders()->get();