php - Symfony2 functional tests + Doctrine fixtures: Changes to entity won't save after flushing in doctrine fixtures -
i've encountered problem while executing fixtures functional tests in symfony 2.6. in fixture have function creating base entity , flushing database. call function other functions change newly-created entity more elaborate (like setting relationships other entities) , flush again.
however, when check database, second flush makes no changes entity.
i've tried debugging , see unitofwork contains nothing scheduled insertion/update before second flush, although execute functions set....().
do have idea doing wrong?
here excerpt fixture:
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(); // 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 forcing our own id on entity, can force // of entities loaded in fixture , id of // entity stays same no matter how many other entities have // been loaded before. crucial in our functional tests, // can go 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 changes function $this->addreference($referencename, $application); return $application; } }
any appreciated, thank in advance!
okay, time me being stupid.
we've changed application - installercontractor relationship many-to-many (from one-to-many we've had previously), instead of using
setinstallercontractor()
i had use
addinstallercontractor()
thank's derstoffel help, try https://github.com/liip/liipfunctionaltestbundle!
Comments
Post a Comment