robo
robo

Reputation: 45

yii2 codeception application class wrong

When I change the application model in my acceptance test, the test acutally uses that model, when I do the same in functional test... the test still uses yii/web/application I need it to use my common/compontents/application model. How can I change that ?

The functional _bootstrap contains my custom model... (common/compontents/application) I am totally baffled....

When I run my testing code:

use tests\codeception\frontend\FunctionalTester;
$I = new FunctionalTester($scenario);
$I->amOnPage('/');

Then I get the error:

[yii\base\UnknownPropertyException] Getting unknown property: yii\web\Application::nowSQL

This nowSQL is defined in common\components\application, but somehow this functional test uses the default

Acceptance yml


    # Codeception Test Suite Configuration

    # suite for acceptance tests.
    # perform tests in browser using the Selenium-like tools.
    # powered by Mink (http://mink.behat.org).
    # (tip: that's what your customer will see).
    # (tip: test your ajax and javascript by one of Mink drivers).

    # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

    class_name: AcceptanceTester
    modules:
        enabled:
            - PhpBrowser
            - tests\codeception\common\_support\FixtureHelper
    # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
    # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
    # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
    # it is useful if you want to login in your app in each test.
    #        - WebDriver
        config:
            PhpBrowser:
    # PLEASE ADJUST IT TO THE ACTUAL ENTRY POINT WITHOUT PATH INFO
                url: http://example.com
    #        WebDriver:
    #            url: http://localhost:8080
    #            browser: firefox
    #            restart: true

Functional .YML


    # Codeception Test Suite Configuration

    # suite for functional (integration) tests.
    # emulate web requests and make application process them.
    # (tip: better to use with frameworks).

    # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
    #basic/web/index.php
    class_name: FunctionalTester
    modules:
        enabled:
          - Filesystem
          - Yii2
          - tests\codeception\common\_support\FixtureHelper
        config:
            Yii2:
                configFile: '../config/frontend/functional.php'

Upvotes: 0

Views: 454

Answers (1)

buddha
buddha

Reputation: 161

In order to use your custom application class for functional tests, set the 'class' configuration in your 'functional.php' config.

functional.suite.yml:

class_name: FunctionalTester
modules:
    enabled:
      - Yii2
    config:
        Yii2:
            configFile: 'codeception/config/functional.php'

functional.php:

return [
    'class' => 'my\custom\Application',
    ...
];

Regarding acceptance testing you have to change the Application implementation used in your index-text.php:

[...]
(new my\custom\Application($config))->run();

Upvotes: 0

Related Questions