【问题标题】:Set different Input for Codeigniter My_ciunit Controller testing为 Codeigniter My_ciunit 控制器测试设置不同的输入
【发布时间】:2012-12-10 18:59:08
【问题描述】:

我知道如何设置和执行控制器以对其进行测试。

查看框架链接https://bitbucket.org/kenjis/my-ciunit

但是我如何定义给定的测试数据输入?当然我可以自己设置 $_GET 和 $_POST 但是输入库会重新解析这个吗?

我在谷歌上找不到答案。我也想知道为什么 Codeigniter 测试的谷歌结果如此糟糕。

<?php

/**
  * @group Controller
  */

class SomeControllerTest extends CIUnit_TestCase
{
public function setUp()
{
    // Set the tested controller
    $this->CI = set_controller('welcome');
}

public function testWelcomeController()
{

    // Call the controllers method
    $this->CI->index();

    // Fetch the buffered output
    $out = output();
            $viewData = viewvars();

    // Check if the content is OK
    $this->assertSame(0, preg_match('/(error|notice)/i', $out));
}

    public function testInput(){

        //reset $_GET and $_POST?

        $this->CI->login();

        //assert valid login etc ...
    }

}

【问题讨论】:

    标签: php codeigniter testing phpunit


    【解决方案1】:

    是的,您需要自己在测试设置中或任何最有意义的地方手动设置 $_GET 和 $_POST 值,例如:

    public function setUp()
    {
        // Set the tested controller
        $this->CI = set_controller('welcome');
        // Set up the input values
        $_GET['parameter_1'] = 'Some String';
        $_GET['parameter_2'] = 123;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多