Answer the question
In order to leave comments, you need to log in
How can I lock a component that works with the database?
Hello.
There is a method with such content. How can I lock the work with the database so that I can test such methods?
return \Yii::$app->getDb()
->createCommand()
->insert('user_package', [
'user_id' => 1,
'package_id' => 2,
'created_at' => time(),
'expired_at' => time() * 3600
])
->execute();
Answer the question
In order to leave comments, you need to log in
You can also do this if PHPUnit.
(We make a fake object with the necessary methods)
And at the beginning
Yii::$container->set('db', $mockObject );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question