[Doctrine] ManyToMany Relationships not persisted in database with haveInRepository nested entity creation
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
Piste de recherche
Commencez par tests/functional/ManytoManyEntitiesCest.php et la configuration de Doctrine2 dans functional.suite.yml, puis suivez la manière dont haveInRepository gère les données imbriquées de entityB. Vérifiez le mapping ManyToMany attendu et la syntaxe de l’assertion par rapport à l’état signalé de la base de données. La tâche est terminée lorsque les entités sont créées, que la table de jointure contient la relation et que l’assertion finale seeInRepository réussit.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
Provide console output if related. Use
-vvvmode for more details.
vagrant@symfonyvm:/var/www/mtm$ php vendor/bin/codecept run
Codeception PHP Testing Framework v3.1.2
Powered by PHPUnit 8.5.0 by Sebastian Bergmann and contributors.
Running with seed:
App\Tests.acceptance Tests (0) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
App\Tests.functional Tests (1) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Testing App\Tests.functional
✖ ManytoManyEntitiesCest: Try to test (0.07s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
App\Tests.unit Tests (0) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 326 ms, Memory: 28.25 MB
There was 1 failure:
---------
1) ManytoManyEntitiesCest: Try to test
Test tests/functional/ManytoManyEntitiesCest.php:tryToTest
Step See in repository "App\Entity\EntityA",{"entityB":{"name":"Name B"}}
Fail App\Entity\EntityA with {"entityB":{"name":"Name B"}}
Failed asserting that false is true.
Scenario Steps:
4. $I->seeInRepository("App\Entity\EntityA",{"entityB":{"name":"Name B"}}) at tests/functional/ManytoManyEntitiesCest.php:24
3. $I->seeInRepository("App\Entity\EntityA",{"name":"Name A"}) at tests/functional/ManytoManyEntitiesCest.php:23
2. $I->seeInRepository("App\Entity\EntityB",{"name":"Name B"}) at tests/functional/ManytoManyEntitiesCest.php:22
1. $I->haveInRepository("App\Entity\EntityA",{"name":"Name A","entityB":[{"name":"Name B"}]}) at tests/functional/ManytoManyEntitiesCest.php:19
FAILURES!
Tests: 1, Assertions: 3, Failures: 1.
Provide test source code if related
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\EntityARepository")
*/
class EntityA
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\EntityB", inversedBy="entityA")
*/
private $entityB;
}
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\EntityBRepository")
*/
class EntityB
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\EntityA", mappedBy="entityB")
*/
private $entityA;
}
public function cannotSeeManyToManyRelationships(FunctionalTester $I)
{
$I->haveInRepository(
EntityA::class,
[
'name' => 'Name A',
'entityB' =>[[ 'name' => 'Name B' ]],
]);
$I->seeInRepository(EntityB::class, ['name' => 'Name B']);
$I->seeInRepository(EntityA::class, ['name' => 'Name A']);
$I->seeInRepository(EntityA::class, ['entityB' => ['name' => 'Name B']]);
}
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
- Codeception version: Codeception PHP Testing Framework v3.1.2
- PHP Version: 7.2
- Operating System: Ubuntu 18.04
- Installation type: Composer
functional.suite.yml
actor: FunctionalTester
modules:
enabled:
- Symfony:
app_path: 'src'
environment: 'test'
- Doctrine2:
depends: Symfony
cleanup: true
- \App\Tests\Helper\Functional
- Langage dominant
- PHP
- Étoiles
- 4
- Forks
- 2
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de Codeception/module-doctrine
-
Difficulté 3/5 1-2 jours Accessibilité débutants 38/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 30/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
Codeception/module-doctrine#2 · 1 commentaire · 1 réaction ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 42/100
-
Difficulté 3/5 1-2 jours Accessibilité débutants 64/100
Codeception/module-doctrine#6 · 1 commentaire ·
Toutes les issues de Codeception/module-doctrine
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
MagnaCapax/PMSS#1142 · 1 commentaire ·
Les mainteneurs répondent en général sous 3 jours
-
bug 🐛
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
netalertx/NetAlertX#1856 · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
Bug Status: Needs Triage
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
feature good first issue html mcv php
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
lorisleiva/laravel-docker#166 ·