A
A
Askar Fuzaylov2016-07-01 15:11:26
Yii
Askar Fuzaylov, 2016-07-01 15:11:26

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

2 answer(s)
S
Sergey Andreev, 2016-07-01
@DragorWW

There are fixtures, here is the guide

D
devian3000, 2016-07-05
@devian3000

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 question

Ask a Question

731 491 924 answers to any question