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); }
Likewise, PHPUnit mock object is a simulated object that performs the behavior of a part of the application that is required in the unit test. The developers control the mock object by defining the pre-computed results on the actions.
PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. The currently supported versions are PHPUnit 9 and PHPUnit 8.
The assertEquals() function is a builtin function in PHPUnit and is used to assert whether the actual obtained value is equals to expected value or not. This assertion will return true in the case if the expected value is the same as the actual value else returns false.
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, ...., ], ]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With