2012-02-23 9 views
5

non ho potuto trovare alcunché di simile, e sto cercando di indovinare che non esiste ..È possibile ottenere il test corrente nel dispositivo setUp?

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? 
    } 
} 

risposta

6

$this->name deve contenere il nome del metodo TestCase corrente. Puoi accedervi (come David ha gentilmente indicato) con $this->getName().

Controllare l'API per TestCase a https://github.com/sebastianbergmann/phpunit/blob/3.6/PHPUnit/Framework/TestCase.php. Scorri le proprietà e i loro commenti per avere un'idea di ciò che è disponibile.

+1

'$ name' è stato modificato in privato, quindi è necessario utilizzare' $ this-> getName() '. –

+0

Questo l'ha fatto, grazie! – velo9

+0

In effetti, la fonte è il modo migliore per trovare ciò che è disponibile. :) –

Problemi correlati