Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2功能测试&x2B;条令固定装置:变更实体赢得';在内存中刷新后无法保存_Php_Symfony_Doctrine Orm_Functional Testing_Fixtures - Fatal编程技术网

Php Symfony2功能测试&x2B;条令固定装置:变更实体赢得';在内存中刷新后无法保存

Php Symfony2功能测试&x2B;条令固定装置:变更实体赢得';在内存中刷新后无法保存,php,symfony,doctrine-orm,functional-testing,fixtures,Php,Symfony,Doctrine Orm,Functional Testing,Fixtures,在Symfony 2.6中执行功能测试的夹具时遇到问题。在fixture中,我有一个创建基本实体并将其刷新到数据库的函数。然后,我从其他函数调用此函数,这些函数将新创建的实体更改为更复杂的内容(如设置与其他实体的关系),然后再次刷新 但是,当我检查数据库时,第二次刷新不会更改实体 我尝试过调试,我看到UnitOfWork在第二次刷新之前没有包含任何计划插入/更新的内容,尽管我执行了函数set…() 你知道我做错了什么吗 以下是我的夹具摘录: class LoadTestApplications

在Symfony 2.6中执行功能测试的夹具时遇到问题。在fixture中,我有一个创建基本实体并将其刷新到数据库的函数。然后,我从其他函数调用此函数,这些函数将新创建的实体更改为更复杂的内容(如设置与其他实体的关系),然后再次刷新

但是,当我检查数据库时,第二次刷新不会更改实体

我尝试过调试,我看到UnitOfWork在第二次刷新之前没有包含任何计划插入/更新的内容,尽管我执行了函数set…()

你知道我做错了什么吗

以下是我的夹具摘录:

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;
    }
}

感谢您的帮助,提前谢谢

好吧,这次是我太傻了

我们最近将应用程序与InstallerContractor的关系更改为多对多(从一对多,我们以前已经这样做了),因此不再使用

setInstallerContractor()
我不得不使用

addInstallerContractor()

感谢德斯托菲尔的帮助,我们一定会努力的

这有助于您管理测试的装置:您确定以正确的顺序执行它们吗?另外,如果实体不是新创建的,则不需要调用$manager->persist();冲洗就足够了。