phpUnit - Functions in test class that aren't tests


April 2019


625 time


I'm doing some speed comparisons between reports in phpunit, as I am trying to figure out an optimization problem.

I have a couple of functions that aren't necessarily tests, but don't belong in the functionality of the project either. I am using them in order to make my tests small and readable. The function I am using does a cUrl operation with the parameters I pass to it.

So, I am running two Urls (two versions of a project, one in its original form, and one with the optimization) and seeing if they return text equal to each other. I would not do this within the app itself. I'm doing this because its quicker than trying to figure out the correct function calls because the project is a bit messy.

So I have a test like this:

public function testOne(){

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


And my two non test functions:

protected function testRange($fromDay,

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


    return $this->testRunner();


protected function testRunner(){

    $response = array();

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

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


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



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

        $dump = "logs/report_results/".

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


    return $result;


I'm wondering if

A: it is possible to write functions in the test file, and have phpunit ignore them, or if there is a more appropriate place to put them.

B: there is a more sensible way to handle this sort of thing. I like this approach, but I am open to suggestions.

1 answers


PHPUnit will ignore any method whose name does not start with "test*" and do not have a @Test annotation so feel free to put stuff in private helper functions.