phpUnit-测试类中不是测试的函数

Pau*_*ley 1 php phpunit curl

我正在phpunit中的报告之间进行一些速度比较,因为我试图找出一个优化问题。

我有一些功能不一定要测试,但是也不属于项目的功能。我使用它们是为了使我的测试小巧易读。我正在使用的函数对传递给我的参数执行cUrl操作。

因此,我正在运行两个Urls(一个项目的两个版本,一个版本以其原始形式,一个版本进行了优化),并查看它们是否返回彼此相等的文本。我不会在应用程序本身中执行此操作。我这样做是因为它比尝试找出正确的函数调用要快,因为该项目有点混乱。

所以我有一个像这样的测试:

public function testOne(){

    $results = $this->testRange(13,1,2013,16,1,2013);
    $this->assertEquals($results['opt'], $results['non_opt']);

}//tests
Run Code Online (Sandbox Code Playgroud)

还有我的两个非测试功能:

protected function testRange($fromDay,
                          $fromMonth,
                          $fromYear,
                          $toDay,
                          $toMonth,
                          $toYear){

    $this->params['periodFromDay'] = $fromDay;
    $this->params['periodFromMonth'] = $fromMonth;
    $this->params['periodFromYear'] = $fromYear;
    $this->params['periodToDay'] = $toDay;
    $this->params['periodToMonth'] = $toMonth;
    $this->params['periodToYear'] = $toYear;

    $this->data['from']=$fromDay."-".$fromMonth."-".$fromYear;
    $this->data['to']=$toDay."-".$toMonth."-".$toYear;;

    return $this->testRunner();

}//testOneDay


protected function testRunner(){

    //include"test_bootstrap.php";
    $response = array();

    foreach($this->types as $key=>$type){

        $params = http_build_query($this->params);
        $url=$this->paths[$type];
        $curl_url = $url."?".$params;
        $ch = curl_init($curl_url);
        $cookieFile = "tmp/cookie.txt";

        if(!file_exists($cookieFile))
        {

            $fh = fopen($cookieFile, "w");
            fwrite($fh, "");
            fclose($fh);

        }//if

        curl_setopt($ch,CURLOPT_COOKIEFILE,$cookieFile);
        curl_setopt($ch,CURLOPT_COOKIEJAR,$cookieFile);
        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch,CURLOPT_HEADER,0);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

        $result[$type] = curl_exec($ch);

        $dump = "logs/report_results/".
                 $this->data['from']."_".
                 $this->data['to']."_".
                 $type.".txt";

        $fh = fopen($dump, "w");
        fwrite($fh, $result[$type]);
        fclose($fh);

    }//foreach

    return $result;

}//testRunner
Run Code Online (Sandbox Code Playgroud)

我想知道

答:可以在测试文件中编写函数,并让phpunit忽略它们,或者是否有放置它们的合适位置。

B:有一种更明智的方式来处理这种事情。我喜欢这种方法,但我愿意接受建议。

lat*_*ell 5

PHPUnit将忽略名称不以“ test *”开头且没有@Test注释的任何方法,因此可以随时将其放入私有帮助器函数中。