Running a PHPUnit testcase multiple times

php, phpunit, testcase

Solution

I think Sven's is answer is correct. Write what you want to set, and give the test case parameter you need, like:

/**
 * @dataProvider forMyTest
 */
public function testWithDifferentDbType($type, $param1, $param ....)
{
    $this->assertExists(....);
}

public function forMyTest() {
    return [
        [
            true
            [$prodDb, $param1, $param, .....],
        ],
        [   
            false,
            [$debugDb, $param1 $param, ....,

        ],
    ];
}

Problem

I'm looking for a way how to run a testcase multiple times with different setting. I'm testing a database access class (dozens of test methods), and want to test it in "normal mode" and then in "debug mode". Both modes must produce the same test results. Is there any possibility to do that in the testcase setting? Or overriding the run() method? I don't want to write the test twice, of course :) Thank you edit: GOT IT! ``` public function run(PHPUnit_Framework_TestResult $result = NULL) { if ($result === NULL) { $result = $this->createResult(); } /** * Run the testsuite multiple times with different debug level */ $this->debugLevel = 0; print "Setting debug level to: " . $this->debugLevel . PHP_EOL; $result->run($this); $this->debugLevel = 8; print "Setting debug level to: " . $this->debugLevel . PHP_EOL; $result->run($this); $this->debugLevel = 16; print "Setting debug level to: " . $this->debugLevel . PHP_EOL; $result->run($this); return $result; } public function setUp() { parent::setUp(); $this->myclass->setOptions('debug', $this->debugLevel); } ```

Original source

Related problems