S
S
Sergey Beloventsev2018-04-24 10:37:11
Yii
Sergey Beloventsev, 2018-04-24 10:37:11

How to put a stub on a method with an associated model?

Actually the question is in the following there is such a code

$sessionResourceOption->resourceOptions->getSeatsCount();

where
$sessionResourceOption is the SessionResourceOption class;
resourceOptions is the link to the class ResourceOptions
here is the link
public function getResourceOptions()
    {
        return $this->hasOne(ResourceOptions::className(), ['id' => 'resource_options_id']);
    }

getSeatsCount() is the ResourceOptions method
I do this
$this->getSeatsCount=Stub::make(new ResourceOptions(),['getSeatsCount'=2]);
$this->sessionResourceOption=Stub::make(new BookingSessionResourceOption (),'resourceOptions',$this->getSeatsCount)

But I am getting an error
Could not add property resourceOptions, class app\models\BookingSessionResourceOption implements __set method, and no resourceOptions property exists

to the bottom line. What's wrong ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-04-24
@Sergalas

Good morning.
Try like this
Although...
Show the method getSeatsCount()and write what it does.
Perhaps it would be more correct to make it static and call it in the following way with parameter passing
ResourceOptions::getSeatsCount($param)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question