Comments (19)
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.
App\User\:
resource: '../src/User/'
exclude:
- '../src/User/**/{Entity,ValueObject,CompilerPass}/**' <<< THIS ONE
- '../src/User/**/ApiPlatform/{Dto,Resource}/**'
- '../src/User/**/*Exception.php'
from foundry.
ok, thanks, good to know... this is... very strange! 😅
from foundry.
Hello, I think perhaps your factories are not being autowired/autoconfigured. Can you find the service with bin/console debug:container
?
from foundry.
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.
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.
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.
Closing as stale. If you're still having issues, let me know and I'll reopen.
from foundry.
@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.
@Perf where is your userfacrory located? It needs to be autoconfigured/autowired.
from foundry.
@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.
Hmm, ok, can you find the factory with debug:container?
from foundry.
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.
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.
Hi @Perf
with this
service.yaml
, you should be able to retrieveApp\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.
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.
I'm curious to know the origin of the problem, when you'll find it out!
from foundry.
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.
yes but, which one was excluding the path src/User/Doctrine/Factory/UserFactory
? 🤔
from foundry.
Related Issues (20)
- [Foundry 2] Allow objects creation in data provider HOT 2
- support "in-memory" repositories HOT 2
- Problem with dama and reset database
- Add Faker `optional()` by default for nullable fields HOT 6
- Should object be scheduled for insert before afterInstantiate call ? HOT 3
- Error with DAMA + reset mode migrate + global story HOT 8
- [Feature] Add a event before/after reset database (and schema creation) HOT 7
- [Question] [Help needed] How to filter data returned by `random` based on type? HOT 1
- Proxy objetc TypeError HOT 2
- Possibility to "merge" properties in user land HOT 1
- Metadata in doc-comments is deprecated HOT 4
- Database Resetter with Multiple mapper HOT 2
- Double call Zenstruck\Foundry\Proxy->object() generates RuntimeException('Cannot auto refresh "Entity" as there are unsaved changes. Be sure to call ->save() or disable auto refreshing')
- How to get the EntityManager used by foundry? HOT 3
- Errors in ORM3/DBAL4 HOT 2
- Support need for specific cases HOT 6
- Using story pools without persisting
- [2.x] Deprecations / Upgrading w/o Symfony's Deprecation Helper HOT 3
- [2.x] [rector] error thrown using `FoundrySetList` && `PersistenceResolver` w/ custom generator HOT 2
- [1.x] [upgrade] `ModelFactory` to `ObjectFactory` with services throws `\RuntimeException` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foundry.