Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Doctrine/EntityRegenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function regenerateEntities(string $classOrNamespace)
$embeddedClasses = [];

foreach ($classMetadata->embeddedClasses as $fieldName => $mapping) {
if (false !== strpos($fieldName, '.')) {
continue;
}

$className = $mapping['class'];

$embeddedClasses[$fieldName] = $this->getPathOfClass($className);
Expand Down
12 changes: 12 additions & 0 deletions tests/Maker/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,18 @@ public function getCommandEntityTests()
->setRequiredPhpVersion(70100)
];

yield 'entity_regenerate_embeddable_object' => [MakerTestDetails::createTest(
$this->getMakerInstance(MakeEntity::class),
[
// namespace: use default App\Entity
'',
])
->setArgumentsString('--regenerate')
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntityRegenerateEmbeddableObject')
->configureDatabase()
->setRequiredPhpVersion(70100)
];

yield 'entity_regenerate_embeddable' => [MakerTestDetails::createTest(
$this->getMakerInstance(MakeEntity::class),
[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Embeddable()
*/
class Currency
{
/**
* @var string
*
* @ORM\Column(name="currency", type="string")
*/
private $currency;

public function __construct($currency)
{
$this->currency = $currency;
}

/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}

/**
* @param string $currency
* @return Currency
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}


}
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 Invoice
{
/**
* @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\Money")
*/
private $total;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

class Money
{
/**
* @var Currency
*
* @ORM\Embedded(class="App\Entity\Currency")
*/
private $currency;

/**
* @var int
*
* @ORM\Column(name="amount", type="integer")
*/
private $amount;

public function __construct($amount, Currency $currency)
{
$this->amount = $amount;
$this->currency = $currency;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Tests;

use App\Entity\Invoice;
use Money\Currency;
use Money\Money;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Doctrine\ORM\EntityManager;

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\\Invoice i')->execute();

$invoice = new Invoice();
// check that the constructor was instantiated properly
$this->assertInstanceOf(Money::class, $invoice->getTotal());
// fields should now have setters
$invoice->setTitle('Borscht');

$total = new Money(100, new Currency('EUR'));
$invoice->setTotal($total);

$em->persist($invoice);

$em->flush();
$em->refresh($invoice);

/** @var Invoice[] $actualInvoice */
$actualInvoice = $em->getRepository(Invoice::class)
->findAll();

$this->assertcount(1, $actualInvoice);

/** @var Money $actualTotal */
$actualTotal = $actualInvoice[0]->getTotal();

$this->assertInstanceOf(Money::class, $actualTotal);
}
}