N
N
nepster-web2015-09-14 15:26:29
PHP
nepster-web, 2015-09-14 15:26:29

Where to get access_token when testing RestApi with Codeception?

I came across such a thing, all my api is closed for unauthorized users, so you must first get a token.
That is, before all the tests, you need to execute the code, get the token, put it in the amBearerAuthenticated method and run all the tests.
As I fields all tests should be executed in any order and not depend on each other.
I can get the token in every test in the _before method:

class GroupResponseCest
{
    public function _before(ApiTester $I)
    {
        // получить токен
        $I->amBearerAuthenticated($token);
    }

    public function all(ApiTester $I)
    {
    }
}

However, then the base is clogged and constant duplication of code. There is also a _bootstrap.php file, but I did not understand how you can get methods for requests to api from there.
Please tell me how can I get a token immediately before running all the tests?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question