A
A
Anton2016-08-22 06:51:40
Yii
Anton, 2016-08-22 06:51:40

How to run codecaption unit tests on yii2 advanced?

Hello. I want to run unit tests but it doesn't work, it
gives this error:

[yii\base\InvalidConfigException]
  The "id" configuration for the Application is required.

The only config that I have changed is frontend/config.php
Here is its content:
return [
    'language' => 'en-US',
    'components' => [
        'db' => [
            'dsn' => 'mysql:host=localhost;dbname=mytest',
            'username' => 'root',
            'password' => '',
        ],
        'mailer' => [
            'useFileTransport' => true,
        ],
        'urlManager' => [
            'showScriptName' => true,
        ],
    ],
];

File content frontend\unit\_bootstrap.php:
$application = new yii\web\Application(__DIR__. '/../../config/frontend/unit.php');

File content frontend\codeception.yml:
namespace: tests\codeception\frontend
actor: Tester
paths:
    tests: .
    log: _output
    data: _data
    helpers: _support
settings:
    bootstrap: _bootstrap.php
    suite_class: \PHPUnit_Framework_TestSuite
    colors: true
    memory_limit: 1024M
    log: true
config:
    # the entry script URL (with host info) for functional and acceptance tests
    # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
    test_entry_url: http://localhost:8080/frontend/web/index-test.php
modules:
  config:
    Db:
      dsn: 'mysql:host=localhost;dbname=mytest'
      user: 'root'
      password: ''

File content frontend\unit.suite.yml:
class_name: WebGuy
modules:
  enabled:
    - Db

I run the tests with a command codecept run unitfrom the folder tests\codeception\frontend
Also phpstorm does not see the Unit class
b0f9d01b00784c46812640be9202140e.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2016-08-22
@qonand

well, in this case, your error clearly says that the application identifier is not set in the config, which is required for work

A
Anton Reitarovskiy, 2016-08-22
@Antonchik

I solved the error by adding the id parameter to the config/frontend/config/unit.php

return yii\helpers\ArrayHelper::merge(
    require(YII_APP_BASE_PATH . '/common/config/main.php'),
    require(YII_APP_BASE_PATH . '/common/config/main-local.php'),
    require(YII_APP_BASE_PATH . '/frontend/config/main.php'),
    require(YII_APP_BASE_PATH . '/frontend/config/main-local.php'),
    require(dirname(__DIR__) . '/config.php'),
    require(dirname(__DIR__) . '/config-local.php'),
    require(dirname(__DIR__) . '/unit.php'),
    require(__DIR__ . '/config.php'),
    [
        'id' => 'app-frontend',
        'basePath' => dirname(__DIR__),
    ]
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question