websupport/codeception-yii-bridge

Codeception YiiBridge 扩展

dev-master 2019-03-08 11:37 UTC

This package is auto-updated.

Last update: 2024-09-21 13:36:01 UTC


README

用于在Codeception中运行Yii功能测试的包装类。目前尚未提供平滑集成。目前仅用于您自己的痛点与风险。

概念

Yii1 框架并非为功能测试而设计。此桥接类包括覆盖标准 Yii 组件以供测试的组件。Yii功能测试中最常见的问题是PHP代码中使用headerscookies函数,这在测试中会产生错误。此外,使用exit指令甚至可能完全停止测试执行。

安装

php composer.phar require "codeception/codeception:*"
php composer.phar update
  • 将Codeception引导到protected/tests
./vendor/bin/codecept bootstrap protected/tests
  • 并设置Yii1模块。

test.php:

<?php

// Definitions
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

// Load the config files
$config = require __DIR__.DS.'protected'.DS.'config'.DS.'test.php';

// Load Yii and Composer extensions
require_once __DIR__.DS.'vendor'.DS.'yiisoft'.DS.'yii'.DS.'framework'.DS.'yii.php';
require_once __DIR__.DS.'vendor'.DS.'autoload.php';

// Return for Codeception
return array(
    'class' => 'CWebApplication',
    'config' => $config,
);

codeception.yml:

actor: Dev
paths:
    tests: protected/tests
    log: protected/tests/_log
    data: protected/tests/_data
    helpers: protected/tests/_helpers
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
    log: true
    debug: true
modules:
    enabled: [PhpBrowser, WebHelper, TestHelper, Yii1]
    config:
        PhpBrowser:
            url: https://:8234
        Yii1:
            appPath: test.php
            url: https://:8234/test.php

  • 通过Composer安装YiiBridge
php composer.phar require "codeception/YiiBridge:*"
php composer.phar update
  • 修改您的protected/config/test.php配置文件,使用CodeceptionHttpRequest类而不是CHttpRequest
<?php return array(
    [...]

    'components' => array(

        [...]

        'request' => array(
            'class' => 'CodeceptionHttpRequest'
        ),

        [...]
    ),
);
  • 完成!正常使用codeception生成运行时测试

重要提示

此桥接功能尚不完整。它可能不适合您的项目。因此,欢迎任何贡献。如果您觉得需要自定义提供的任何类,请这样做。

已知问题和路线图

  • 会话 -> 触发PHP错误
  • 转发 -> 触发PHP错误
  • CLocale -> 触发错误
  • HTTP状态码
  • WebApplication->end -> 触发exit指令

致谢

初始版本由Ragazzo创建。