【问题标题】:Codeception namespaces代码接收命名空间
【发布时间】:2017-05-24 01:49:48
【问题描述】:

目前我们有一个使用 Codeception 2.0.16 构建的大型验收套件。 我们想升级到 Codeception 2.2.5。但是,在安装 Codeception 2.2.5(通过 phar)之后,我们根本无法运行我们的测试套件。

我们收到的错误是(底部的其他详细信息):

[代码接收\异常\配置异常] 无法找到和加载模块 WebHelper

显然,新版本的加载更改会影响我们的套件。

我已搜索迁移说明以帮助我们进行此升级,但没有看到任何说明。

其他详情

  • 代码接收版本:2.016 ==> 2.2.5
  • PHP 版本:5.6.9
  • 操作系统:CentOS
  • 安装类型:Phar

Codeception PROJECT 配置

注意:在测试和更改了代码的几个部分后,我注意到主要问题与命名空间有关。正如你在下面看到的,我们使用了一个名为“SM”的命名空间,以及这个操作系统如何导致问题。

codeception.yml

namespace: SM
paths:
    tests: tests
    log: tests/_log
    data: tests/_data
    helpers: tests/_helpers
settings:
    bootstrap: _bootstrap.php
    suite_class: \PHPUnit_Framework_TestSuite
    colors: true
memory_limit: 1024M
    log: true
    strict_xml: true
modules:
    config:
        Db:
            dsn: 'mysql:host=xxxxxxxxxxxx;dbname=<DB_NAME>'
            user: 'USER'
            password: '********'
            dump: tests/_data/dump.sql
            populate: false
            cleanup : false

验收套件配置

class_name: WebGuy
modules:
    enabled:
        - WebDriver
        - WebHelper
        - SistemWSClient
        - TestingSupportWSClient
        - Db
        - TempFileManager
        - Asserts

    config:
        WebDriver:
            url: 'http://xxxxxxxxxxxxxxxxxx/codeception'
            browser : firefox
            host: xxxxxxxxxxxxx
            port: 4444
            wait: 0
            restart: true
            capabilities:
                unexpectedAlertBehaviour: 'accept'

        SistemWSClient:
            url: xxxxxxx
        TestingSupportWSClient:
            url: 'http://x/codeception/rest.php'
        Db:
            dsn: 'mysql:host=xx;port=3306;dbname=x'
            user: 'xxxxxxx'
            password: 'xxxxxxx'
            dump: 'some/dump/file'
            populate: false
            cleanup: false

注意事项:

a) 我添加了“namespace SM;”在 tests/_helpers/WebHelper.php 的顶部(它不起作用)

b)我也试过这个:(没用)

modules:
    enabled:
        - \WebHelper (or \SM\WebHelper or any other combination)

c)我还从 codeception 的网站安装了一个干净的 codeception 版本:

  • 已下载代码接收 (wget http://codeception.com/codecept.phar)
  • 已安装(codecept 引导程序)
  • 仅为测试目的创建了简单的测试(codecept generate:cept accept Welcome)

添加了“命名空间 SM;”和 Helpers 相应地,我得到同样的错误,在这种情况下:

Helper\Acceptance 无法找到并加载

d)我也尝试过使用 codeception 的“add-namespace”命令,但没有运气

任何想法将不胜感激。

谢谢,

【问题讨论】:

    标签: php testing automation namespaces codeception


    【解决方案1】:

    在 Codeception 中,必须构建“助手”。尝试发出命令:

    codecept build
    

    然后再次运行。

    【讨论】:

      【解决方案2】:

      我的案例中的错误提到了另一个文件,但是原因和解决方案可能是相同的。

      经过几个小时的调试和网络搜索,我至少找到了问题的答案: http://phptest.club/t/class-helper-acceptance-does-not-exist/808

      就我而言,我的主要项目的 .gitignore 中有一个 _* 行。因此,尚未提交 codeception 目录,特别是包含所请求文件的 _support 目录。

      从我的 .gitignore 中删除 _* 行并提交和拉取文件,然后解决问题。

      希望这会有所帮助。

      【讨论】:

      • 这个答案与问题无关!
      猜你喜欢
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2019-12-04
      相关资源
      最近更新 更多