据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,非常感谢,我现在明白了。 –