Php 为Codeigniter My_ciunit控制器测试设置不同的输入
我知道如何设置和执行控制器来测试它 请参阅框架链接 但是如何定义给定的测试数据输入?当然,我可以自己设置$\u GET和$\u POST,但是输入库会重新分析它吗 我在谷歌找不到答案。我还想知道为什么Codeigniter测试的谷歌结果如此糟糕Php 为Codeigniter My_ciunit控制器测试设置不同的输入,php,codeigniter,testing,phpunit,Php,Codeigniter,Testing,Phpunit,我知道如何设置和执行控制器来测试它 请参阅框架链接 但是如何定义给定的测试数据输入?当然,我可以自己设置$\u GET和$\u POST,但是输入库会重新分析它吗 我在谷歌找不到答案。我还想知道为什么Codeigniter测试的谷歌结果如此糟糕 <?php /** * @group Controller */ class SomeControllerTest extends CIUnit_TestCase { public function setUp() { // S
<?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 ...
}
是的,您需要在测试设置中或任何最有意义的地方手动设置$\u GET和$\u 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;
}
是的,您需要在测试设置中或任何最有意义的地方手动设置$\u GET和$\u 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;
}