From 653cd13ad857c9ee88e2b41a121812865b0d8a57 Mon Sep 17 00:00:00 2001 From: Takashi Kanemoto Date: Thu, 9 Oct 2025 11:34:54 +0900 Subject: [PATCH 1/3] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20add=20a=20note?= =?UTF-8?q?=20that=20factories=20under=20`App\Tests\Factory\`=20must=20be?= =?UTF-8?q?=20registered=20in=20the=20service=20container=20when=20using?= =?UTF-8?q?=20`make:factory=20--test`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 1355a89c6..cdaf5c25c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -181,6 +181,21 @@ This command will generate a ``PostFactory`` class that looks like this: Using ``make:factory --test`` will generate the factory in ``tests/Factory``. + If your entity has some properties with Doctrine relationships, the factories for the related entities must be registered + in the service container so that the maker command can find them. To do that, add the following to your ``services.yaml``. + + .. code-block:: yaml + + # config/packages/services.yaml + when@dev: + services: + _defaults: + autowire: true + autoconfigure: true + + App\Tests\Factory\: + resource: '../tests/Factory/' + .. tip:: You can globally configure which namespace the factories will be generated in: From f4c759a790c207af86bc7f14a15df8902d61265b Mon Sep 17 00:00:00 2001 From: Takashi Kanemoto Date: Fri, 10 Oct 2025 17:28:08 +0900 Subject: [PATCH 2/3] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20modify=20the?= =?UTF-8?q?=20wording=20and=20configuring=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index cdaf5c25c..28165055b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -181,21 +181,21 @@ This command will generate a ``PostFactory`` class that looks like this: Using ``make:factory --test`` will generate the factory in ``tests/Factory``. - If your entity has some properties with Doctrine relationships, the factories for the related entities must be registered - in the service container so that the maker command can find them. To do that, add the following to your ``services.yaml``. +.. tip:: + + When using ``--test`` flag, we're still dealing with ``dev`` environment. And because we want the container to know about our factories, + we need to declare them as services even if they are in the ``tests`` directory. To do that, add the following to your configuration: .. code-block:: yaml - # config/packages/services.yaml + # config/packages/zenstruck_foundry.yaml when@dev: services: - _defaults: + App\Tests\Factory\: + resource: '../../tests/Factory/' autowire: true autoconfigure: true - App\Tests\Factory\: - resource: '../tests/Factory/' - .. tip:: You can globally configure which namespace the factories will be generated in: From 19da7a8a3e238865d1339e0baecd75bf0bea093a Mon Sep 17 00:00:00 2001 From: Takashi Kanemoto Date: Fri, 10 Oct 2025 17:52:35 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20improve=20the=20`tes?= =?UTF-8?q?ts`=20directory=20path=20notation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 28165055b..a4befee73 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -192,7 +192,7 @@ This command will generate a ``PostFactory`` class that looks like this: when@dev: services: App\Tests\Factory\: - resource: '../../tests/Factory/' + resource: '%kernel.project_dir%/tests/Factory/' autowire: true autoconfigure: true