6

I use the codecept functional testing for test my APIs in yii2.I put the arguments hardcoded for testing like this

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

I wanted to give that arguments while I running the test case by codecept run functional loginCept or save that arguments in one file and assign to the test case when I run the test.How should I achieve this?

1
  • I have same problem, How to automate the functional testing in yii2? Commented Oct 17, 2015 at 8:04

1 Answer 1

3

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

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

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

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

Use it in your test code the same way you call params in a regular Yii application. It doesn't matter whether it is unit, functional etc.

Yii::$app->params['user.login'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.