【问题标题】:Codeception Content-disposition assert fileCodeception 内容处置断言文件
【发布时间】:2016-04-22 10:09:34
【问题描述】:

我想声明一个 xls 文件。我回来了:

"attachment; filename="testify.xlsx""

如何对文件进行断言?

我有来自$_SERVER['TMPDIR'] 的 tmp 路径和干净的文件名,但目录中没有文件。

【问题讨论】:

    标签: codeception


    【解决方案1】:

    没有为此目的的内置方法,您必须编写自己的helper

    如果您使用的是 PhpBrowser 或其中一个框架模块,它们有两个有用的隐藏方法: _getResponseContent 返回页面(或文件)内容,
    _savePageSource 将其保存到文件中。

    所以你的辅助方法看起来像这样:

    function seeXlsFileIsValid()
    {
        $fileContent = $this->getModule('PhpBrowser)->_getResponseContent();
        $this->assertTrue(..., 'returned xls file is not valid');
    }
    

    如果要声明响应头,请从REST module 复制 seeHttpHeader 方法。

    【讨论】:

    • 只在 $this->getModule('PhpBrowser')->_getResponseContent() 上返回空字符串...还有其他想法吗?
    • 还有 $this->getModule('PhpBrowser')->_savePageSource(codecept_output_dir().'page.html');正在制作空白页
    • 是的,但您还必须在 php 浏览器 curl 中使用此设置:CURLOPT_RETURNTRANSFER: true
    • 不,你不能。我试图重现您的问题,但 _getResponseContent() 在所有情况下都返回字符串。您是否应该告诉我您在测试中使用的其他异常参数?
    【解决方案2】:

    codeception.yml

    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
        shuffle: true
    extensions:
        enabled:
            - Codeception\Extension\RunFailed
    coverage:
      enabled: true
      c3_url: 'http://www-dev.testify.com:8080/c3.php'
      remote: false
      whitelist:
          include:
              - _php/*
    

    api.suite.yml

    class_name: ApiTester
    modules:
        enabled:
            - PhpBrowser:
                url: http://www-dev.testify.com:8080
                clear_cookies: false
                restart: false
                curl:
                  CURLOPT_RETURNTRANSFER: true
            - REST:
                url: http://www-dev.testify.com:8080
                depends: PhpBrowser
                part: Json
            - Asserts
            - Helper\Api
            - Db:
                dsn: 'sqlite:tests/_output/database.sqlite'
                user: ''
                password: ''
    env:
        fast:
    

    【讨论】:

      猜你喜欢
      • 2021-02-27
      • 1970-01-01
      • 2014-11-28
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      相关资源
      最近更新 更多