Yii Framework Forum: [SOLVED] Does unit test work with scenarios? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED] Does unit test work with scenarios?

#1 User is offline   ateshabaev 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 19-August 15

Posted 09 July 2017 - 10:18 AM

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';


        expect_that($model->save());

    }


Error it happening on this line:

expect_that($model->save());



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.
0

#2 User is offline   ateshabaev 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 19-August 15

Posted 09 July 2017 - 11:41 AM

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?

This post has been edited by ateshabaev: 09 July 2017 - 11:42 AM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users