2012-12-10 80 views
1

我知道如何設置和執行一個控制器來測試它。設置Codeigniter My_ciunit控制器測試的不同輸入

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

但我怎麼能確定給定的測試數據輸入?當然,我可以自己設置$ _GET和$ _POST,但是輸入庫重新解析了這個嗎?

我無法在Google上找到答案。我也想知道爲什麼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 ... 
    } 

}

回答

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; 
}