Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Refactor static state #8

Merged
merged 15 commits into from
Jun 22, 2020
Merged

[POC] Refactor static state #8

merged 15 commits into from
Jun 22, 2020

Conversation

kbond
Copy link
Member

@kbond kbond commented Jun 19, 2020

Attempt to make foundry configurable with the bundle. Still allows foundry to be used without the bundle.

TODO:

  • Add bundle services (Manager, StoryManager, Faker, Instantiator)
  • Bundle config:
    zenstruck_foundry:
        faker:
            service: ~ # for complete control
            locale: ~ # to configure a different locale (only applicable if `service` above is not configured)
        instantiator:
            service: ~ # for complete control
            without_constructor: false # only applicable if `service` above is not configured
            allow_extra_attributes: false # only applicable if `service` above is not configured
            always_force_properties: false # only applicable if `service` above is not configured
  • Story service auto-configuration
  • Boot factory in ZenstruckFoundryBundle::boot()? This will allow using factories/stories in your doctrine fixtures with zero config.
  • allow for configuring if not using bundle (in tests/bootstrap.php). I'm thinking of a Configuration static class with setFaker()/setInstantiator() methods. When booting, if this has been configured, it takes precedence over bundle config. (ensure works with GlobalState)
  • Bundle service/config tests
  • Documentation

Base automatically changed from unpersisted-proxy to refactor June 19, 2020 17:21
@kbond kbond mentioned this pull request Jun 19, 2020
24 tasks
- make Manager constructor arguments required
- remove Manager::boot()
- make Manager/StoryManager services
- call Factory::boot() in ZenstruckFoundryBundle::boot()
- add test to ensure stories as services are loaded correctly
- proxies created in global state would have a different "Manager" than the
one used in your tests causing the om to think these were not persisted.
Always grabbing the current manager from Factory::manager() solves this.
- also removed injecting into RepositoryProxy to be consistent.
src/Bundle/Resources/config/services.xml Outdated Show resolved Hide resolved
src/Factory.php Show resolved Hide resolved
src/Test/Configuration.php Outdated Show resolved Hide resolved
@kbond
Copy link
Member Author

kbond commented Jun 22, 2020

I renamed Test/Configuration to Test/TestState (better name suggestion welcome) and using without the bundle must be enabled specifically with TestState::withoutBundle().

I also merged GlobalState into TestState as they both related to test-only static configuration.

@kbond
Copy link
Member Author

kbond commented Jun 22, 2020

I renamed Manager to Configuration

@kbond
Copy link
Member Author

kbond commented Jun 22, 2020

One thing that kind of sucks is if you want your dev and test config to match, you have to duplicate it in config/packages/dev/zenstruck_foundry.yaml and config/packages/test/zenstruck_foundry.yaml

Maybe the recipe could try to solve this by having the test config import the dev?

src/Configuration.php Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants