Open Pryrios opened 4 years ago
Update: If I create the entities manually instead of using haveInRepository the test passes, so it seems the syntax of the last assertion is correct.
I can confirm, I have tried to write a test for API call where I have ManyToMany relation, and I did not receive expected relation in response.
@Pryrios can you post the example how you created the entities manually? I am trying but after I call $em->persist(class), then it fails.
I just created each of the two entities, persisted and flushed the entityManager. Something like:
$entityB = new EntityB("Name B");
$em->persist($entityB);
$entityA = new EntityA("Name A", $entityB);
$em->persist($entityA);
$em->flush();
Please bear in mind that I tested this more than one year ago and I don't remember how I did it manually, this is just what comes to mind.
That would save the entities to the database as well as their relationship which was the missing bit. I dunno why it fails to you. Maybe you are persisting the parent entity but the child one isn't getting persisted?
Is there any chance this can be fixed? I (and assume a lot of others) have lost quite a bit of time on this before I realised it was a bug in the module...
If you know how to fix it, please raise pull request.
I have a similar issue on my project. Functional tests were running fine until I updated libraries (symfony 6.2 -> 6.3) caused this issue. After some investigation we ended up thinking there may be 2 entityManager in the test.
What are you trying to achieve?
I am running a functional test on a Symfony 4 + Doctrine 2 with two entities with a ManyToMany relationship. I create the entities using haveInRepository nested functionality and I expect to have the two entities created on the database and related on the join table.
What do you get instead?
The entities are created but relationships in join tables are not, so the test fails due to missing information on database.
Details
With that setup, the two first seeInRepository pass but the third does not. It could be due to the syntax of the array not being correct on the last assertion as it should really be an array, but if you look into the database you can see that the join table has not been filled.
It may be due a syntax problem, but in that case it should be an issue with docs as it doesn't specify how to work with ManyToMany relationships.
I have created a complete example in this repo: https://github.com/Pryrios/test-manytomany
functional.suite.yml