【问题标题】:Are some Codeception modules incompatible?某些 Codeception 模块是否不兼容?
【发布时间】:2015-12-02 19:41:51
【问题描述】:

我正在使用 Codeception 对 Symfony 项目进行验收测试。我需要测试所有内容,这意味着测试页面(html 内容)以及它们执行的 ajax 调用(JSON 内容)。

我已经在我的套件设置中启用了 Symfony2 模块,但我发现其中没有几个方法可以检查 JSON 字符串,所以我想我也应该启用 REST 模块。但是,如果我这样做,其他先前存在的测试就会失败。

例如,这个简单的测试:

public function privateExtranetHome(AcceptanceTester $I)
{
    $I->wantTo('test something');
    $I->amOnRoute('acme_site_home.es');
    $I->assertEquals(
        'container',
        $I->grabAttributeFrom('#container-slider', 'class')
    );
}

这不是 JSON 测试测试,只是我的 Cest 类中已经存在的测试,当我只启用 Symfony2 模块时它通过了,现在我添加了 REST 模块失败了。错误信息是:

Scenario:
* I am on route "acme_site_home.es"

  [Page] http://localhost/es
  [User] anon. []
* I grab attribute from "#container-slider","class"

Fatal error: Call to a member function hasAttribute() on null in [...]\Codeception\Module\REST.php on line 993

可能amOnRoute() 方法与 REST 模块不兼容,因为启用后者时,我得到一个空响应。但因此我的问题是:是否有一些文档说明哪些模块不兼容并且不应该一起启用?还是我应该根据经验为每个模块使用单独的套件?


以防万一,我的验收套件设置如下:

class_name: AcceptanceTester
modules:
    enabled:
        - Asserts
        - Db
        - Symfony2
        - Doctrine2
        - \Tests\Helper\Acceptance

还有我的 Codeception 设置:

namespace: 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:
        Db:
            dsn: 'mysql:host=localhost;dbname=acme_test'
            user: 'root'
            password: 'blahblah'
            dump: 'tests/_data/dump.sql'
            populate: false
            cleanup: false
        Doctrine2:
            depends: Symfony2
            cleanup: false
        PhpBrowser:
            url: http://acme.com
        WebDriver:
             browser: firefox
             url: http://acme.com
        REST:
            depends: Symfony2
            url: http://acme.com

【问题讨论】:

    标签: php json symfony testing codeception


    【解决方案1】:

    REST 模块与框架模块兼容并依赖于框架模块来处理请求。 但是,您发现了一个未报告的不兼容性——grabAttributeFrom 方法在两个模块——Symfony2 和 REST 中都定义了。我会为此提出一个问题。

    您可以使用一种解决方法 - GrabAttributeFrom 在 REST 模块的 XML 部分中定义,因此如果您的 REST 请求仅返回 JSON,您可以仅启用 JSON 功能。

    REST:
        depends: Symfony2
        part: JSON
    

    【讨论】:

    猜你喜欢
    • 2019-07-21
    • 1970-01-01
    • 2017-02-07
    • 2019-01-08
    • 2016-08-22
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    • 2014-09-09
    相关资源
    最近更新 更多