How to automate functional testing in yii2?

I use kodazu functional testing to test my APIs in yii2.I put arguments hard-coded for testing like this

use tests\codeception\backend\FunctionalTester; $I = new FunctionalTester($scenario); $I->wantTo('Check when authenticated'); $I->sendPOST('/login', ['password' => '11111111', 'email'=>' check@check.com ']); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContains('"result"'); $I->seeResponseContains('"message"'); $I->haveHttpHeader('Accept','application/json'); $I->seeResponseContains('"message":"OK"'); 

I would like to give these arguments while I run the test script using the codeod launch function. loginCept or save these arguments in a single file and assign a test case when starting the test. How am I supposed to do this?

+5
source share
1 answer

You can create a file in the path / in / your / project / tests / codeception / config called let say params.php. Then add params to the newly created file:

 <?php return [ 'login.email' => ' check@check.com ', 'login.password' => '111111' ]; 

In your path / in / your / project / tests / codeception / config / config.php put this:

 <?php return [ 'components' => [ ... ], 'params' => require(__DIR__ . '/params.php'), ]; 

Use it in the test code in the same way as you call params in a regular Yii application. It does not matter if it is a unit, functionality, etc.

 Yii::$app->params['user.login']; 
+2
source

All Articles