diff --git a/src/Doctrine/EntityRegenerator.php b/src/Doctrine/EntityRegenerator.php index e64470219..567eaea50 100644 --- a/src/Doctrine/EntityRegenerator.php +++ b/src/Doctrine/EntityRegenerator.php @@ -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); diff --git a/tests/Maker/FunctionalTest.php b/tests/Maker/FunctionalTest.php index 7b709353c..9007cb05d 100644 --- a/tests/Maker/FunctionalTest.php +++ b/tests/Maker/FunctionalTest.php @@ -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), [ diff --git a/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Currency.php b/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Currency.php new file mode 100644 index 000000000..d10d1bf5b --- /dev/null +++ b/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Currency.php @@ -0,0 +1,43 @@ +currency = $currency; + } + + /** + * @return string + */ + public function getCurrency() + { + return $this->currency; + } + + /** + * @param string $currency + * @return Currency + */ + public function setCurrency($currency) + { + $this->currency = $currency; + return $this; + } + + +} diff --git a/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Invoice.php b/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Invoice.php new file mode 100644 index 000000000..68ce7ae68 --- /dev/null +++ b/tests/fixtures/MakeEntityRegenerateEmbeddableObject/src/Entity/Invoice.php @@ -0,0 +1,28 @@ +amount = $amount; + $this->currency = $currency; + } +} diff --git a/tests/fixtures/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php b/tests/fixtures/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php new file mode 100644 index 000000000..81a65ae2d --- /dev/null +++ b/tests/fixtures/MakeEntityRegenerateEmbeddableObject/tests/GeneratedEntityTest.php @@ -0,0 +1,48 @@ +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); + } +}