Skip to content

Factory generation fails with nested embeddables #1008

Description

@ostrolucky

Reproducer: Apply this patch and run test Zenstruck\Foundry\Tests\Integration\Maker\MakeFactoryTest::can_create_factory_with_embeddable@orm

Subject: [PATCH] ay
---
Index: tests/Fixture/Model/Embeddable.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/Fixture/Model/Embeddable.php b/tests/Fixture/Model/Embeddable.php
--- a/tests/Fixture/Model/Embeddable.php	(revision 81cc97d213b5e7f8c4bf6c12faddbb169db15c89)
+++ b/tests/Fixture/Model/Embeddable.php	(date 1760613124770)
@@ -25,9 +25,14 @@
     #[ORM\Column(type: 'string')]
     private string $prop1;
 
-    public function __construct(string $prop1)
+    #[ORM\Embedded(class: Embeddable2::class)]
+    #[MongoDB\EmbedOne(targetDocument: Embeddable2::class)]
+    public Embeddable2 $prop2;
+
+    public function __construct(string $prop1, Embeddable2 $prop2)
     {
         $this->prop1 = $prop1;
+        $this->prop2 = $prop2;
     }
 
     public function getProp1(): string
Index: tests/Fixture/Model/Embeddable2.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/Fixture/Model/Embeddable2.php b/tests/Fixture/Model/Embeddable2.php
new file mode 100644
--- /dev/null	(date 1760612398582)
+++ b/tests/Fixture/Model/Embeddable2.php	(date 1760612398582)
@@ -0,0 +1,37 @@
+<?php
+
+/*
+ * This file is part of the zenstruck/foundry package.
+ *
+ * (c) Kevin Bond <kevinbond@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Zenstruck\Foundry\Tests\Fixture\Model;
+
+use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @author Kevin Bond <kevinbond@gmail.com>
+ */
+#[ORM\Embeddable]
+#[MongoDB\EmbeddedDocument]
+class Embeddable2 // not final on purpose
+{
+    #[MongoDB\Field(type: 'string')]
+    #[ORM\Column(type: 'string')]
+    private string $prop1;
+
+    public function __construct(string $prop1)
+    {
+        $this->prop1 = $prop1;
+    }
+
+    public function getProp1(): string
+    {
+        return $this->prop1;
+    }
+}

Result:

ReflectionException: Property Zenstruck\Foundry\Tests\Fixture\Entity\WithEmbeddableEntity::$embeddable.prop2 does not exist

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmaker

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions