Inside a PHPUnit testcase with two or more tests using the same @dataProvider
, I want the provider to find out, which test it is providing data to. I have accomplished this using debug_backtrace()
, but this feels wrong. Does PHPUnit provide another more standard way to achieve this? In case yes, how?
<?php
class MyTest extends \PHPUnit_Framework_TestCase {
/** @dataProvider dataProvider */
public function testA () {}
/** @dataProvider dataProvider */
public function testB () {}
public function dataProvider () {
$trace = debug_backtrace(false, 3);
$caller = $trace[2]['args'][2];
// $caller === 'testA' or $caller === 'testB'
}
}
Aucun commentaire:
Enregistrer un commentaire