Answer the question
In order to leave comments, you need to log in
Unit tests in Yii2. How to mock Active Record static methods?
For example, I have a model.
class MyModel extends Model
{
public function foobar()
{
$customer = Customer::find()->where('age>30')->all();
// bussiness logic
// ..................
}
}
class MyModel extends Model
{
public function doSomething(Customer $customer = NULL)
{
if ($customer === NULL) {
$customer = Customer::find()->where('age>30')->all();
}
// ...
}
}
Answer the question
In order to leave comments, you need to log in
Try to pull the business logic into a separate class that works with the interface and takes what you need from it. In MyModel, implement this interface.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question