Can I unit-test ActiveRecord models without a database connection?

If possible, it would be nice to test some methods in ActiveRecord models without supplying a complete database fixture. Is the only alternative to mock the database connection class?

1 Like

To make things even worse for mocking, components are read-only.

Meh, I’ll just move anything non-db related to service classes instead.

Is this issue solved in Yii 3, by the way?

Or maybe a solution can be to create an interface that extends your model, and then use this interface instead in your service classes?

Solution here: How to mock ActiveRecord

1 Like