Skip to content

feat(factories): add factory craft command and location binding - #55

Open
Roshankc682 wants to merge 2 commits into
masonitedev:5.0from
Roshankc682:feature/30
Open

feat(factories): add factory craft command and location binding#55
Roshankc682 wants to merge 2 commits into
masonitedev:5.0from
Roshankc682:feature/30

Conversation

@Roshankc682

Copy link
Copy Markdown

Summary

  • Adds a factory craft command that scaffolds a model factory class from a stub
  • Wires the stub into the existing masoniteorm.factories.Factory engine (register/make/create, faker integration — already shipped in
    masonite-framework-orm)
  • Adds a factories.location binding (databases/factories), following the exact pattern already used for seeds.location/mailables.location
  • Adds a factories_path() helper in utils/location.py, mirroring seeds_path()

Refs

Partially addresses #30. This PR covers the command + stub + location-binding slice. Not yet covered (open to doing in a follow-up, or splitting further per
maintainer feedback):

  • Auto-discovery of factories (loading them automatically, like seeders)
  • States beyond the existing name= param on Factory.register()
  • Relationship helpers — not present in masoniteorm.factories.Factory at all; would need a change in masonitedev/orm, a separate repo
  • Docs page + release notes entry

Test plan

  • New tests added: tests/features/factories/test_make_factory_command.py (command creates factory, --model override, --force overwrite protection),
    test_factories_path in tests/core/utils/test_location.py
  • Full suite: pytest tests -m "not integrations" — 700 passed, 22 failed (all pre-existing, environment-only: Windows path separators, missing
    Pillow/ffmpeg — unrelated to this change)

Let me know once it's pushed and I'll double check the diff on GitHub before you submit, if you'd like.

Scaffolds model factories via a new factory command and stub, wired into the existing masoniteorm.factories.Factory engine, following the same command/location pattern already used for jobs, seeds and mailables.

Refs #30

Scaffolds model factories via a new `factory` command and stub, wired
into the existing masoniteorm.factories.Factory engine, following the
same command/location pattern already used for jobs, seeds and mailables.

Refs masonitedev#30
…ependency

The generated factory hardcoded `app.models.<model>` as the import path,
which only works when models.location is the skeleton default; it now
derives the import from wherever models.location actually points, same
as the rest of the framework's location-aware commands.

Also request masonite-framework-orm's `seeder` extra so `faker` is
installed, without which Factory.make()/create() always raised
ImportError. Added an end-to-end test that generates a factory, imports
it for real, and creates + queries a persisted record through it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant