[SOLVED] Does unit test work with scenarios?

Does unit test work with scenarious?

I keep on getting error:

Test  tests/unit/models/ModeNameTest.php:testSuccess


  [yii\base\ErrorException] Trying to get property of non-object 

This is the code for testSuccess method in ModeNameTest model:

public function testSuccess()


        $model = new UserNamesTestModel(['scenario' => UserNamesTestModel::SCENARIO_CLIENT]);

        $model->user_id = 1;

        $model->name = 'Test Name';



Error it happening on this line:


UserNamesTestModel extends ActiveRecord, thefore such method as save(), update() should be there and I have no idea why it is throwing such Exception…

Did anybody cross this problem before?

P.s. it is not related to rules validation, because $model->errors return empty array.

Okay, I found the problem, but do not know how to solve another issue now:

I have method defined as validation rules in my model and it has Yii::$app->user->identity->id, which takes authorized user id to check whatever about him.

This is why it throws Exception.

But how can I make test in this case if I am making a simple unit test?