webfactory / doctrine-orm-test-infrastructure

Provides utils to create a test infrastructure for Doctrine ORM entities.
MIT License
20 stars 5 forks source link

Entity imported twice in case of bi-directional cascade #20

Closed Matthimatiker closed 7 years ago

Matthimatiker commented 7 years ago

Entities are imported twice, when there is a bi-directional cascade configuration:

// [...]
class List {
    // [...]
    /**
     * @OneToMany(targetEntity="Item", mappedBy="list", cascade={"all"})
     * @var Collection of Item objects
     */
     private $items;
}

// [...]
class Item {
    // [...]
    /**
     * @ManyToOne(targetEntity="List", inversedBy="items", fetch="EAGER", cascade={"persist"})
     * @JoinColumn(referencedColumnName="id")
     * @var List
     */
    private $list;
}

// [...]
$infrastructure->import($item)

This is caused by \Webfactory\Doctrine\ORMTestInfrastructure\Importer::importFromCallback() in combination with \Webfactory\Doctrine\ORMTestInfrastructure\DetachingObjectManagerDecorator, which executes flush() twice: