Codeception Object配置必须是一个数组

时间:2018-09-26 07:12:44

标签: yii2 codeception

我正在尝试运行基本的代码接收测试,但是出现以下错误:

Backend\tests.functional Tests (1) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
E LoginCest: Login user (0.01s)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1) LoginCest: Login user
 Test  tests/functional/LoginCest.php:loginUser

  [yii\base\InvalidConfigException] Object configuration must be an array containing a "class" element.  


Scenario Steps:

 1. $I->amOnPage("/admin/user/login") at tests/functional/LoginCest.php:18

#1  /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/BaseYii.php:353
#2  /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/base/Module.php:427
#3  /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/base/Module.php:586
#4  /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/base/Module.php:522
#5  /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/web/Application.php:103
#6  /home/projects/toma/toma-coreshop/vendor/symfony/browser-kit/Client.php:351
#7  Codeception\Lib\InnerBrowser->amOnPage
#8  /home/projects/toma/toma-coreshop/backend/tests/_support/_generated/FunctionalTesterActions.php:526
#9  /home/projects/toma/toma-coreshop/backend/tests/functional/LoginCest.php:18
#10 backend\tests\functional\LoginCest->loginUser


Time: 251 ms, Memory: 16.00MB

There was 1 error:

---------

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

在这些测试中,错误一步一步地流过。我的配置文件看起来像(backend\codeception.yml):

namespace: backend\tests
actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
modules:
    config:
        Yii2:
            configFile: 'config/test.php'

在我的test.php中,我有:

<?php
$config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/main.php'),
    require(__DIR__ . '/main-local.php'),
    [
        'id' => 'app-backend-test',
        'components' => [
            'db' => [
                'class' => 'yii\db\Connection',
                'dsn' => 'mysql:host=localhost;dbname=coreshop',
                'username' => '*****',
                'password' => '*****',
                'charset' => 'utf8',
                //'enableSchemaCache' => true,
            ],
        ]
    ]
);
return $config;

最后是我的LoginCest.php

/**
 * Class LoginCest
 */
class LoginCest
{
    /**
     * @param FunctionalTester $I
     */
    public function loginUser(FunctionalTester $I)
    {
        $I->amOnPage('/admin/user/login');
        $I->fillField('Username', '***');
        $I->fillField('Password', '***');
        $I->click('Вход');
    }
}

我遵循了代码接收站点上关于Yii2-advanced模板的指示。我正在尝试在旧项目上进行测试,因此在这种情况下,它不是新安装的Yii2-advanced。谢谢! 编辑 Main.php:     

$params = array_merge(
        require(__DIR__ . '/../../common/config/params.php'),
        require(__DIR__ . '/../../common/config/params-local.php'),
        require(__DIR__ . '/params.php'),
        require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-backend',
    'name' => 'Online Shop Admin',
    'homeUrl' => '/admin',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'backend\controllers',
    'language' => 'bg-BG',
    'bootstrap' => [
        [
            'class' => 'app\components\LanguageSelector',
            'supportedLanguages' => [],
        ],
        'log',
        'devicedetect'
    ],
    'modules' => [
        'user' => [
            'controllerMap' => [
                'security' => 'backend\controllers\user\SecurityController',
                'admin' => 'backend\controllers\user\AdminController',
            ],
            'modelMap' => [
                'User' => 'backend\models\User',
                'SettingsForm' => 'backend\models\SettingsForm',
                'Profile' => 'backend\models\Profile',
                /*'UserSearch' => 'backend\models\UserSearch',*/
            ],
            'rememberFor' => 1209600,
        ],
        'statistics' => [
            'class' => 'backend\modules\statistics\Module',
        ],
        'catalogue' => [
            'class' => 'backend\modules\catalogue\Module',
        ],
        'news' => [
            'class' => 'backend\modules\news\Module',
        ],
        'sales' => [
            'class' => 'backend\modules\sales\Module',
        ],
        'wasteManagment' => [
            'class' => 'backend\modules\wasteManagment\WasteManagment',
        ],
        'help' => [
            'class' => 'backend\modules\help\HelpInfo',
        ],
        'marketing' => [
            'class' => 'backend\modules\marketing\Module',
        ],
        'translation' => [
            'class' => 'backend\modules\translation\Module',
        ],
        'gii' => [
            'class' => 'yii\gii\Module',
            'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1'], // adjust this to your needs
            'generators' => [
                'crud'   => [
                    'class'     => 'backend\templates\crud_v1\Generator',
                    'templates' => ['mycrud' => '@backend/templates/crud_v1/default']
                ],
                'model'   => [
                    'class'     => 'backend\templates\model_v1\Generator',
                    'templates' => ['mymodel' => '@backend/templates/model_v1/default']
                ],
                /*'crud'   => [
                    'class'     => 'backend\templates\crud_module_v1\Generator',
                    'templates' => ['mycrudmodule' => '@backend/templates/crud_module_v1/default']
                ],
                'model'   => [
                    'class'     => 'backend\templates\model_module_v1\Generator',
                    'templates' => ['mymodelmodule' => '@backend/templates/model_module_v1/default']
                ],*/
            ],
        ],
    ],
    'components' => [
        'assetManager' => [
            'bundles' => [
                'yii\bootstrap\BootstrapAsset' => [
                    'css' => [],
                ],
                'yii\bootstrap\BootstrapPluginAsset' => [
                    'js' => []
                ],
                'yii\web\JqueryAsset' => [
                    'js' => []
                ],
                'wbraganca\dynamicform\DynamicFormAsset' => [
                    'js' => [
                        '/admin/dist/js/yii2-dynamic-form.js'
                    ]
                ],
            ],
        ],
        'urlManagerBackend' => [
            'class' => 'yii\web\urlManager',
            'baseUrl' => (isset($_SERVER['HTTPS']) ? "https" : 'http') . "://toma-coreshop.webbuild.com/admin",
            'enablePrettyUrl' => true,
            'showScriptName' => false,
        ],
        'request' => [
            'baseUrl' => '/admin',
            'cookieValidationKey' => 'sew4789vb7834tvnv78',
            'csrfParam' => '_backendCSRF',
        ],
        'user' => [
            'identityClass' => 'backend\models\User',
            'enableAutoLogin' => true,
            'loginUrl' => [ 'user/login'],
            'identityCookie' => [
                'name' => '_backendUser', // unique for backend
            ]
        ],
        /*'session' => [
            'name' => '_backendSessionId',
            'savePath' => __DIR__ . '/../runtime/sessions',
        ],*/
        'view' => [
            'theme' => [
                'pathMap' => [
                    '@dektrium/user/views' => '@backend/views/user',
                    '@dektrium/rbac/views' => '@backend/views/rbac',
                ],
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
        ],
        'translate' => [
            'class' => 'backend\components\Translate'
        ],
        'tabSettings' => [
            'class' => 'backend\components\TabSettings'
        ],
        'system' => [
            'class' => 'backend\components\System'
        ],
        'moneyConvertor' => [
            'class' => 'backend\components\MoneyConvertor'
        ],
        'moneyWords' => [
            'class' => 'backend\components\MoneyWords'
        ],
        'OutData' => [
            'class' => 'backend\components\OutData'
        ],
        'MakeURL' => [
            'class' => 'backend\components\MakeURL'
        ],
        'makeUrl' => [
            'class' => 'frontend\components\MakeURL'
        ],
        'image' => [
            'class' => 'backend\components\Image'
        ],
        'formatter' => [
            'class' => 'yii\i18n\Formatter',
            'nullDisplay' => '',
        ],
        'devicedetect' => [
            'class' => 'alexandernst\devicedetect\DeviceDetect'
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            'rules' => [
                'profile' => 'user/settings/profile',
            ],
        ],
        'i18n' => [
            'translations' => [
                'app*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/messages',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'app' => 'app.php',
                    ],
                ],
                'help*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/modules/help/messages',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'help' => 'help.php',
                    ],
                ],
                'sales*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/modules/sales/messages',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'catalogue' => 'sales.php',
                    ],
                ],
                'statistics*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/modules/statistics/messages',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'catalogue' => 'statistics.php',
                    ],
                ],
                'catalogue*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/modules/catalogue/messages',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'catalogue' => 'catalogue.php',
                    ],
                ],
                'marketing*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/modules/marketing/messages',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'catalogue' => 'news.php',
                    ],
                ],
                'news*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/modules/news/messages',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'catalogue' => 'news.php',
                    ],
                ],
                'message*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/modules/translation/messages',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'message' => 'message.php',
                    ],
                ],
                'kvgrid*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@backend/messages/kvgrid',
                    'sourceLanguage' => 'bg',
                    'fileMap' => [
                        'kvgrid' => 'kvgrid.php',
                    ],
                ],
            ],
        ],
    ],
    'params' => $params,
];

Main-local.php:

$config = [
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'ud_6581BcmdaOC-RoK4LznBhsD7W4pyU',
        ],
    ],
    'container' => [
        'definitions' => [
            kartik\grid\GridView::class => [
                'krajeeDialogSettings' => ['overrideYiiConfirm' => false],
                'responsiveWrap' => false,
                'bordered' => false,
                'tableOptions' => [
                    'class' => 'table full-color-table full-dark-table hover-table',
                ],
                'resizableColumns' => true,
                'hover' => true,
                'layout' => "{items}\n{summary}\n{pager}",
                'rowOptions' => function ($model) {
                    if(!empty($model->id))
                        return ['data-id' => $model->id];
                    else
                        return;
                },
            ],
        ],
    ],
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
    ];
    $config['modules']['debug']['allowedIPs'] = ['*'];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];
    $config['modules']['gii']['allowedIPs'] = ['*'];
}

return $config;

0 个答案:

没有答案