A
A
Artem2019-02-24 13:23:17
Yii
Artem, 2019-02-24 13:23:17

How to use the application object created from Codeception in complex acceptance testing?

Hello. The question is this. Started writing acceptance tests for Yii2 applications.
Came across the following:

public function landToFirstEnterApplication(AcceptanceTester $I)
    {
        /** @var UrlManager $urlManager */
        $urlManager = Yii::$app->get('frontendUrlManager');

        $I->amOnUrl($urlManager->getHostInfo());
        $I->see('Авторизация');

        $I->click('Зарегистрироваться');
        $I->see('Зарегистрироваться');
        $I->fillField(['id' => 'emailform-email'], $userEmail = '[email protected]');
        $I->click('Продолжить');
        $I->waitForText('Вернуться на главную страницу', 2);

        $I->seeEmailIsSent(1);
        /** @var Message $mail */
        $mail = $I->grabLastSentEmail();
        expect($mail->getTo())->hasKey($userEmail);

        $link = $this->getLink($mail->getSwiftMessage()->getChildren()[0]->getBody());
        $I->amOnUrl($link);
        $I->see('Установить пароль');

    }

The test crashes on $I->seeEmailIsSent(1);
This happens because the current instance of Yii::$app created inside the test uses a test stub from Codeception, which puts all letters to itself in a private array.
Then the seeEmailIsSent method and everything next to it works with this array.
And $I itself now uses an application object, simply created from a test config, in which mailer is not replaced by a class from Codeception.
Actually, the question is: how to write a test in such a way that Yii::$app from the test is used, and not created upon request?
acceptance.suite.yml

actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 127.0.0.1:44444
browser: chrome
- Yii2:
configFile: 'common/config/test-local.php'
part:
- email
- ORM
- Fixtures
- init
cleanup: false
transaction: false
recreateApplication: true

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