bscheshirwork/codeception-db-yii2-config

将 'Db' codeception 模块连接到 'Yii2' 模块数据库设置

v2.0.0 2018-10-03 15:17 UTC

This package is auto-updated.

Last update: 2024-09-08 06:37:11 UTC


README

将 'Db' codeception 模块连接到 'Yii2' codeception 模块数据库设置

codeception.yml 中不再需要 db 设置!

删除重复的设置 dsnusernamepassword,请参阅以下内容

示例 backend/codeception.yml

namespace: backend\tests
actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
extensions:
    enabled:
        - Codeception\Extension\RunFailed
modules:
    config:
        Yii2:
            configFile: 'config/test-local.php'

示例 common/config/main-local.php (包含在 backend/config/test-local.php 中)

<?php
return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=db;dbname=yii2advanced',
            'username' => 'yii2advanced',
            'password' => 'yii2advanced',
            'charset' => 'utf8',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
    ],
];

示例 backend/tests/acceptance.suite.yml

class_name: AcceptanceTester
modules:
    enabled:
# See docker-codeception-run/docker-compose.yml: "ports" of service "nginx" is null; the selenium service named "firefox"
# See nginx-conf/nginx.conf: listen 80 for frontend; listen 8080 for backend
        - WebDriver:
            url: http://nginx:8080/
            host: firefox
            port: 4444
            browser: firefox
        - \bscheshirwork\Codeception\Module\DbYii2Config:
            dump: ../common/tests/_data/dump.sql #relative path from "codeception.yml"
        - Yii2:
            part:
              - email
              - ORM
              - Fixtures

注意:Db 模块是第一个(恢复转储),Yii2 模块是第二个(加载测试数据)

安装

将以下内容添加到您的测试环境 composer.json

    "require": {
        "bscheshirwork/codeception-db-yii2-config": "^2.0"
    }