【问题标题】:Cakephp test via phpunit that uses both POST and GET dataCakephp 通过使用 POST 和 GET 数据的 phpunit 进行测试
【发布时间】:2014-02-12 23:57:21
【问题描述】:

我正在使用 Cakephp 的内置测试框架在 Cakephp 中构建一个测试套件。我遇到了以下问题。我有一个控制器方法,在执行时会同时使用GET 和POST 数据。我知道要通过测试模拟GET 数据,您可以轻松地包含以下内容:

$result = $this->testAction('/api/checkuser/', array('data' => $data, 'method' => 'get');

可以为POST 做同样的事情,如下所示:

$result = $this->testAction('/api/currentuser/', array('data' => $data, 'method' => 'post');

但我不确定如何将两者结合使用。有谁知道如何将POST 和GET 数据发送到给定的测试。感谢任何可以提供帮助的人。

【问题讨论】:

  • $this->testAction('/api/checkuser/10', array('data' => $data, 'method' => 'post') 呢?因此,您通过 get 发送用户 ID,其余通过 POST 发送
  • @cornelb 这听起来像是我必须做的。好主意。

标签: php unit-testing cakephp phpunit cakephp-2.0


【解决方案1】:

我从来不需要同时发送 GET 和 POST 数据,但如果可以的话,我想它会是这样的。

$result = $this->testAction('/api/currentuser/', array('data' => $data, 'method' => array('post', 'get'));

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2014-12-25
    • 1970-01-01
    • 2017-08-14
    • 2011-06-02
    • 2014-08-02
    • 2019-01-07
    • 2011-10-10
    • 2012-04-22
    • 2019-08-19
    相关资源
    最近更新 更多