Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get the current test in setUp fixture?

I couldn't find any such thing, and I'm guessing it doesn't exist..

class Test extends PHPUnit_Framework_TestCase {
    public function setUp() {
        echo $current_test; // Output a string "testOne"
    }

    public function testOne() {
        // This is the first test; before this test is ran setUp() is called.
        // The question is, is there any way to know within setUp() what the 
        // current test is?
    }
}
like image 656
velo9 Avatar asked Feb 23 '12 01:02

velo9


1 Answers

$this->name should contain the current testcase method name. You can access it (as David kindly pointed out) with $this->getName().

Check out the API for TestCase at https://github.com/sebastianbergmann/phpunit/blob/3.6/PHPUnit/Framework/TestCase.php. Skim over the properties and their comments to get an idea of what's available.

like image 134
Mike B Avatar answered Nov 10 '22 13:11

Mike B