mercredi 1 juin 2016

How to mock Yii2 component behavior in acceptance test?

I want to test my application behavior using Selenium. But I want the Yii::$app component behavior can be mocked from the test runner?

Let's say I have a class

Foo extends \yii\base\Component {
     public function bar() {
         //return something
     }
}

And in the configuration I attach as Yii::$app component as Yii::$app->foo.

[
    'foo' => [
        'class' => 'Foo',
    ]
]

So the acceptance test works by running a web server and the test runner will run Selenium against the web server.

In the test runner I want to mock the Yii::$app->foo->bar() method so that it will return some string.

How should I do this mock the application component in the application run by the web server from the test runner?

Aucun commentaire:

Enregistrer un commentaire