2015-06-03 23 views
0

我在Symfony 2.6中執行我的功能測試時遇到了問題。在燈具中,我有一個創建基本實體並將其刷新到數據庫的功能。然後我從其他函數調用這個函數,這些函數會將新創建的實體更改爲更精細的內容(例如設置與其他實體的關係),然後再次刷新。Symfony2功能測試+學說固定裝置:在教條夾具中沖洗後實體的變化不會保存

但是,當我檢查數據庫時,第二次刷新不會更改實體。

我試過調試,我看到的是,雖然我執行函數設置....()。在第二次刷新之前,UnitOfWork包含沒有計劃插入/更新的內容。

你知道我在做什麼錯嗎?

下面是摘自我的燈具:

class LoadTestApplications extends AbstractFixture implements OrderedFixtureInterface 
{ 
    const APPLICATION_ID_NOT_SUBMITTED_VALID = 37; 

    public function load(ObjectManager $manager) 
    { 
     //other lines ommitted 

     $this->loadNotSubmittedValidApplication($manager); 

     //other lines ommited 
    } 

    private function loadNotSubmittedValidApplication(ObjectManager $manager) 
    { 
     $application = $this->createAndGetFilledApplication($manager, self::APPLICATION_ID_NOT_SUBMITTED_VALID, 
      'property-property-empty', 'GROUP_INSTALLER', 'application-application-not-submitted-valid', 
      'person-default', 'person-default', 'person-default', 'person-default'); 

     /** @var Installer $installer */ 
     $installer = $this->getReference('installer-installer1'); 

     /** @var InstallerContractor $installerContractor */ 
     $installerContractor = $this->getReference('installer-installer-contractor1'); 

     $application->setInstaller($installer); 
     $installer->addApplication($application); 

     $application->setInstallerContractor($installerContractor); 
     $installerContractor->addApplication($application); 

     $manager->persist($installer); 
     $manager->persist($installerContractor); 
     $manager->persist($application); 
     $manager->flush(); // this saves no changes 
    } 

    private function createAndGetFilledApplication(ObjectManager $manager, $applicationId, $propertyReference, 
     $acg, $referenceName, $contactReference, $improverReference, $billPayerReference, $propertyOwnerReference) 
    { 
     $application = new Application(); 
     $application->setId($applicationId); 

     // lots of other set...() functions 


     // that's for forcing our own ID on the entity, so we can force only 
     // some of the entities to be loaded in the fixture and the id of 
     // the entity stays the same no matter how many other entities have 
     // been loaded before. This is crucial in our functional tests, so 
     // we can go to e.g. http://..../application/15/show 
     /** @var ClassMetadata $metadata */ 
     $metadata = $manager->getClassMetadata(get_class($application)); 
     $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); 

     $manager->flush(); //this saves all changes from this function 

     $this->addReference($referenceName, $application); 

     return $application; 
    } 
} 

任何幫助表示讚賞,感謝你在前進!

+0

這可以幫助您管理測試的燈具:https://github.com/liip/LiipFunctionalTestBundle您確定您以正確的順序執行它們嗎?另外,如果實體不是新創建的,則不需要調用$ manager-> persist();沖洗就足夠了。 – DerStoffel

回答

0

好的,這一次我是愚蠢的。

我們最近改變了應用程序 - InstallerContractor關係到許多一對多(從一到多,我們已經以前有),所以不是使用

setInstallerContractor() 

我不得不使用

addInstallerContractor() 

感謝DerStoffel的幫助,我們一定會嘗試https://github.com/liip/LiipFunctionalTestBundle

相關問題