-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Doctrine embedded entity 'make:entity --regenerate' bugfix
- Loading branch information
1 parent
c7c8f72
commit 0e36480
Showing
6 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/fixtures/MakeEntityRegenerateEmbedable/src/Entity/Food.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
*/ | ||
class Food | ||
{ | ||
/** | ||
* @ORM\Column(name="id", type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(name="title", type="string", length=255) | ||
*/ | ||
private $title; | ||
|
||
/** | ||
* @ORM\Embedded(class="App\Entity\Recipe") | ||
*/ | ||
private $recipe; | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/fixtures/MakeEntityRegenerateEmbedable/src/Entity/Recipe.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Embeddable() | ||
*/ | ||
class Recipe | ||
{ | ||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
private $ingredients; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
private $steps; | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/fixtures/MakeEntityRegenerateEmbedable/tests/GeneratedEntityTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Tests; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Doctrine\ORM\EntityManager; | ||
use App\Entity\Food; | ||
use App\Entity\Recipe; | ||
|
||
class GeneratedEntityTest extends KernelTestCase | ||
{ | ||
public function testGeneratedEntity() | ||
{ | ||
self::bootKernel(); | ||
/** @var EntityManager $em */ | ||
$em = self::$kernel->getContainer() | ||
->get('doctrine') | ||
->getManager(); | ||
|
||
$em->createQuery('DELETE FROM App\\Entity\\Food f')->execute(); | ||
|
||
$food = new Food(); | ||
// check that the constructor was instantiated properly | ||
$this->assertInstanceOf(Recipe::class, $food->getRecipe()); | ||
// fields should now have setters | ||
$food->setTitle('Borscht'); | ||
|
||
$recipe = new Recipe(); | ||
$recipe->setIngredients('ingridients'); | ||
$recipe->setSteps('steps'); | ||
$food->setRecipe($recipe); | ||
|
||
$em->persist($food); | ||
|
||
$em->flush(); | ||
$em->refresh($food); | ||
|
||
/** @var Food[] $actualFood */ | ||
$actualFood = $em->getRepository(Food::class) | ||
->findAll(); | ||
|
||
$this->assertcount(1, $actualFood); | ||
|
||
/** @var Recipe $actualRecipe */ | ||
$actualRecipe = $actualFood[0]->getRecipe(); | ||
|
||
$this->assertInstanceOf(Recipe::class, $actualRecipe); | ||
$this->assertEquals('ingridients', $actualRecipe->getIngredients()); | ||
$this->assertEquals('steps', $actualRecipe->getSteps()); | ||
} | ||
} |