據this documentation,我可以在我的測試類寫一個setUp()
功能,如:爲什麼在不被調用的情況下執行該方法?
use Doctrine\ORM\Tools\SchemaTool;
use Liip\FunctionalTestBundle\Test\WebTestCase;
class AccountControllerTest extends WebTestCase
{
public function setUp()
{
$em = $this->getContainer()->get('doctrine')->getManager();
if (!isset($metadatas)) {
$metadatas = $em->getMetadataFactory()->getAllMetadata();
}
$schemaTool = new SchemaTool($em);
$schemaTool->dropDatabase();
if (!empty($metadatas)) {
$schemaTool->createSchema($metadatas);
}
$this->postFixtureSetup();
$fixtures = array(
'Acme\MyBundle\DataFixtures\ORM\LoadUserData',
);
$this->loadFixtures($fixtures);
}
//...
}
但是,當我尋找在擴展WebTestCase類setUp()
方法,我並不覺得。我的理解是,我可以從子類中的父類重新定義方法。父類是:
https://github.com/liip/LiipFunctionalTestBundle/blob/master/Test/WebTestCase.php
請爲何以及何時得到執行這種方法向我解釋?謝謝
https://github.com/sebastianbergmann/phpunit/blob /master/src/Framework/TestCase.php#L2210遍歷所有類。這是方法的起源。 –
@E_p,非常感謝,我現在明白了。 –