无法为Yii2启用代码测试

时间:2017-07-27 14:49:12

标签: selenium testing yii2 codeception

我在为Yii2网站配置Codeception验收测试时遇到问题。

测试运行正常,但我想更改配置,因此测试联系表单不会发送任何电子邮件。它应该是非常简单的任务,但我不能强迫它使用替代配置。

遵循本教程:http://codeception.com/for/yii

/codeception.yml:

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

/tests/acceptance.suite.yml

class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: http://localhost/mypage
            browser: firefox
        - Yii2:
            part: orm
            entryScript: index.php
            cleanup: false
            configFile: test.php

我再也不知道这个文件指向哪个目录。我尝试使用/config/test.php,/tests/config/test.php,没有。

/config/test.php

<?php
$params = require(__DIR__ . '/params.php');
$dbParams = require(__DIR__ . '/test_db.php');

/**
 * Application configuration shared by all test types
 */
return [
    'id' => 'basic-tests',
    'basePath' => dirname(__DIR__),    
    'language' => 'en-US',
    'components' => [
        'db' => $dbParams,
        'mailer' => [
            'useFileTransport' => true, // <--- I'm interested in this setting 
        ],
        'urlManager' => [
            'showScriptName' => true,
        ],
        'user' => [
            'identityClass' => 'app\models\User',
        ],        
        'request' => [
            'cookieValidationKey' => 'test',
            'enableCsrfValidation' => false,
            // but if you absolutely need it set cookie domain to localhost
            /*
            'csrfCookie' => [
                'domain' => 'localhost',
            ],
            */
        ],        
    ],
    'params' => $params,
];

我甚至认为这条路径可能与/ tests目录相关,所以我也在那里创建了文件:

/tests/config/test.php

<?php
// config/test.php
$config =  yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/main.php'),
    require(__DIR__ . '/main-local.php'),
    [
        'id' => 'app-tests',
        'components' => [
            'db' => [
                'dsn' => 'mysql:host=localhost;dbname=yii_app_test',
            ],
            'mailer' => [
                'useFileTransport' => true
            ]
        ]
    ]
);
return $config;

/tests/_bootstrap.php

<?php
define('YII_ENV', 'test');
defined('YII_DEBUG') or define('YII_DEBUG', true);

require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require __DIR__ .'/../vendor/autoload.php';

部分/config/web.php检查是否传递了环境值,但它们不是

if (YII_ENV_TEST || YII_ENV === 'test'){
    die('Testing settings loaded');
}

使用./vendor/bin/codecept run tests/acceptance/ContactCest.php

启动我的测试

我不会发布测试因为它们无关紧要,因为它们只是使用点击元素来发送联系表单。 目前我浪费了4个小时试图覆盖该配置文件。可能这是一个愚蠢的新秀错误,但我现在就要放弃了。

帮助我,StackOverflow,你是我唯一的希望! ;)

0 个答案:

没有答案