Unit Testing using different sqlite file - connection override in model
I'm hoping someone can either explain what I'm doing wrong, or whether this is just the way it is. My setup is as follows:
- Default connection string: default ( DB_CONNECTION env)
- Alt connection string: alt
- Testing connection string: testing
In a model class I use the protected $connection variable to set which connection to use when not using default so in some instances; $connection = 'alt';
With the unit testing, I have the phpunit.xml file with testing DB_CONNECTION override and I can see through debugging that it does switch to it as expected for testing, using the testing connection. However, because of the set connection in the model, this seems to be taking precedent. In the unit test I've even tried using $model->setConnection('testing')->all(); for example and it still uses the alt connection string even if I debug $model->setConnection('testing'); which says in the debug that the connection is "testing".
So for example in the alt connection on a model I have say 23 records, in testing I have 5 seeded, the unit test always returns the 23 count not 5.
Is this usual behaviour, is there something I'm missing?
Thanks
Please or to participate in this conversation.