我使用Symfony2和PHPUnit與Doctrine並編寫插件包。我有一個擴展Symfony的WebTestCase的TestCase類。Symfony2:在PHPUnit中創建模式一次只運行一個命令
在setUp方法中,我需要創建一個用於測試和加載一些燈具的模式。
我的代碼(如下)正在構建一個應用程序內核,引導一個應用程序,然後運行幾個命令來刪除一個架構,如果它存在,重新創建它並加載一些數據裝置。
我得到的問題是,當在應用程序上使用run()方法時,它只運行第一個命令,然後測試停止,標記爲成功,沒有錯誤或消息。
爲了執行下一個命令,我需要推薦第一個命令並再次運行測試。
很明顯,我想要的結果是每個方法按順序運行。
/**
* setUp
*
* @return void
**/
public function setUp()
{
parent::setUp();
$this->appKernel = $this->createKernel();
$this->appKernel->boot();
$this->application = new Application($this->appKernel);
$this->em = $this->appKernel->getContainer()->get('doctrine')->getManager();
$this->buildDb();
}
/**
* buildDb
* Builds the DB from the Entities in Acme\TestBundle\Entity
* @return void
**/
private function buildDb()
{
$this->application->run(new ArrayInput(array(
'doctrine:schema:drop',
'--force' => true
)));
$this->application->run(new ArrayInput(array(
'doctrine:schema:create'
)));
$this->application->run(new ArrayInput(array(
'doctrine:fixtures:load',
'--fixtures' => 'tests/SupportFiles/bundles/Acme/TestBundle/DataFixtures/Test'
)));
}