Git Product home page Git Product logo

Comments (19)

Perf avatar Perf commented on May 27, 2024 2

maybe your glob patterns do not work as expected? (although they look good to me)

Foundry does not make funky stuff with dependency injection, beside of tagging classes which extend ModelFactory.

hey @nikophil
good finding, I commented the exclude lines and now UserFactory is up, with proper tag
so, I need to review my excludes...
Thank you very much!

from foundry.

Perf avatar Perf commented on May 27, 2024 2

@nikophil

    App\User\:
        resource: '../src/User/'
        exclude:
            - '../src/User/**/{Entity,ValueObject,CompilerPass}/**' <<< THIS ONE
            - '../src/User/**/ApiPlatform/{Dto,Resource}/**'
            - '../src/User/**/*Exception.php'

from foundry.

nikophil avatar nikophil commented on May 27, 2024 2

ok, thanks, good to know... this is... very strange! 😅

from foundry.

kbond avatar kbond commented on May 27, 2024 1

Hello, I think perhaps your factories are not being autowired/autoconfigured. Can you find the service with bin/console debug:container?

from foundry.

marcinmdev avatar marcinmdev commented on May 27, 2024 1

I've encountered this issue:

  • had GlobalStory as service with param injected in constructor by DI
#services_test.yaml
services:   
    App\Story\GlobalStory:
        arguments:
            $env: 'test'
  • only used in dev/test env
  • ran bin/console doctrine:fixtures:load --append -n => Stories with dependencies (Story services) cannot be used without the foundry bundle.

Fix:
set autoconfigure and autowire true to said service:

#services_test.yaml
services:   
    App\Story\GlobalStory:
        autowire: true
        autoconfigure: true
        arguments:
            $env: 'test'

from foundry.

kbond avatar kbond commented on May 27, 2024 1

https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#stories-as-services describes that the tag is needed (below the example). Could probably make that pop a bit more with it as a note.

from foundry.

kbond avatar kbond commented on May 27, 2024 1

What does your config/services.yaml look like? Any exclusions for src/User?

I tried a branch new symfony new --version=lts with composer require --dev zenstruck/foundry and couldn't re-create your issue. I think it's your config.

from foundry.

kbond avatar kbond commented on May 27, 2024

Closing as stale. If you're still having issues, let me know and I'll reopen.

from foundry.

Perf avatar Perf commented on May 27, 2024

@kbond
I had fresh symfony installation (6.4.1) with zenstruck/foundry v1.36.0.
When trying to create fixtures like:

class AppFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        UserFactory::createMany(25);
    }
}

Or in tests, like:

describe('User Resource', function () {
    it('Fetches Users collection', function () {
        UserFactory::createMany(50);

        $res = $this->getJson('users');

        dd($res->getContent(false));
    });
});

I always getting an error:
Model Factories with dependencies (Model Factory services) cannot be used without the foundry bundle.
However, it's installed with Flex, so bundle it added into bundles.php in test and dev envs.
Also, I tried to serach containers with tag foundry.factory or even just foundry and can't find anything.

from foundry.

kbond avatar kbond commented on May 27, 2024

@Perf where is your userfacrory located? It needs to be autoconfigured/autowired.

from foundry.

Perf avatar Perf commented on May 27, 2024

@Perf where is your userfacrory located? It needs to be autoconfigured/autowired.

it's located under src/ folder (\App\User\Doctrine\Factory\UserFactory) so it should be autoconfigured and autowired. Other classes under src/ are autoconfigured and autowired.

from foundry.

kbond avatar kbond commented on May 27, 2024

Hmm, ok, can you find the factory with debug:container?

from foundry.

Perf avatar Perf commented on May 27, 2024

Hmm, ok, can you find the factory with debug:container?

nope, absolutely nothing found

What does your config/services.yaml look like? Any exclusions for src/User?

parameters:

services:
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    _instanceof:
        App\Shared\Application\Command\CommandHandlerInterface:
            tags:
                - { name: messenger.message_handler, bus: command.bus }

        App\Shared\Application\Query\QueryHandlerInterface:
            tags:
                - { name: messenger.message_handler, bus: query.bus }

    App\User\:
        resource: '../src/User/'
        exclude:
            - '../src/User/**/{Entity,ValueObject,CompilerPass}/**'
            - '../src/User/**/ApiPlatform/{Dto,Resource}/**'
            - '../src/User/**/*Exception.php'

    App\Shared\:
        resource: '../src/Shared/'
        exclude:
            - '../src/Shared/**/{Entity,ValueObject,CompilerPass}/**'
            - '../src/Shared/**/ApiPlatform/{Dto,Resource}/**'
            - '../src/Shared/**/*Exception.php'
            - '../src/Shared/Infrastructure/Symfony/Kernel.php'

from foundry.

nikophil avatar nikophil commented on May 27, 2024

Hi @Perf

with this service.yaml, you should be able to retrieve App\User\Doctrine\Factory\UserFactory with $ bin/console debug:container UserFactory... this is not even related to foundry 🤔

don't you have any other config file? maybe for test environment?

from foundry.

Perf avatar Perf commented on May 27, 2024

Hi @Perf

with this service.yaml, you should be able to retrieve App\User\Doctrine\Factory\UserFactory with $ bin/console debug:container UserFactory... this is not even related to foundry 🤔

Hi @nikophil

$ bin/console de:cont UserFactory

No services found that match "UserFactory".

$ bin/console de:cont --tag=foundry.factory

No tags found that match "foundry.factory".

don't you have any other config file? maybe for test environment?

I have 2 other configs, but they are empty

imports:
    - { resource: services/shared.yaml }
    - { resource: services/user.yaml }

no configs for test env

from foundry.

nikophil avatar nikophil commented on May 27, 2024

maybe your glob patterns do not work as expected? (although they look good to me)

Foundry does not make funky stuff with dependency injection, beside of tagging classes which extend ModelFactory.

from foundry.

nikophil avatar nikophil commented on May 27, 2024

I'm curious to know the origin of the problem, when you'll find it out!

from foundry.

Perf avatar Perf commented on May 27, 2024

I'm curious to know the origin of the problem, when you'll find it out!

I updated excludes to the following and now UserFactory works!

    App\User\:
        resource: '../src/User/'
        exclude:
            - '../src/User/Domain/{Entity,ValueObject}/'
            - '../src/User/Infrastructure/ApiPlatform/{Dto,Resource}/'
            - '../src/User/Infrastructure/Doctrine/DataFixtures/'
            - '../src/User/**/*Exception.php'

    App\Shared\:
        resource: '../src/Shared/'
        exclude:
            - '../src/Shared/Domain/{Entity,ValueObject}/'
            - '../src/Shared/Infrastructure/ApiPlatform/{Dto,Resource}/'
            - '../src/Shared/Infrastructure/Doctrine/DataFixtures/'
            - '../src/Shared/Infrastructure/Symfony/Kernel.php'
            - '../src/Shared/Infrastructure/Symfony/CompilerPass/'
            - '../src/Shared/**/*Exception.php'

Now excludes are more explicit )

from foundry.

nikophil avatar nikophil commented on May 27, 2024

yes but, which one was excluding the path src/User/Doctrine/Factory/UserFactory? 🤔

from foundry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.