Answer the question
In order to leave comments, you need to log in
How to test action in yii2 console controller?
Hello,
How can I test an action in a Yii2 console controller using codeception?
I included the Yii2 module in unit.suite.yml, it contains the path to the application config. I understand that after that the application is available in $this->app. But I can't do $this->app->runAction('controller-name/action-name'). I get the error
[yii\base\ErrorException] Undefined property: tests\codeception\console\path\ConsoleAppTest::$app
Can you tell me how to test console controllers using codeception?
Answer the question
In order to leave comments, you need to log in
Hello.
public function testMyConsoleController()
{
$appConfig = [];
$this->mockApplication($appConfig);
$params = ['foo', 'bar'];
$controller = new MyConsoleController('id', Yii::$app);
$result = $controller->run('action', $params);
$this->assertEquals(0, $result);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question