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

[6.x] Add loadFactoriesFrom method #31133

Merged
merged 1 commit into from Jan 15, 2020
Merged

[6.x] Add loadFactoriesFrom method #31133

merged 1 commit into from Jan 15, 2020

Conversation

@iamgergo
Copy link
Contributor

iamgergo commented Jan 15, 2020

This PR implements a new loadFactoriesFrom method in the service providers.
This method works like loadRoutesFrom or loadMigrationsFrom methods.


Usage:

$this->loadFactoriesFrom('source/database/factories');

$this->loadFactoriesFrom([
    'source_one/database/factories', 
    'source_two/database/factories',
]);

Right now, there is no way to use a package's factories that are using models provided by the package itself. For testing the package and the application integration, it's easier to use the package's factories if there is any, instead of rewrite the factories.

Right now, packages can't load their own factories like migrations, views or routes, however it may be a help to the developers to use the package factories easily as well.

orchestral/testbench offers something similar to solve this for package testing:

$this->withFactories(__DIR__.'/../database/factories');

I did not find any tests for the route or migration loading from the provider and right now I don't see how to test this easily. This is why I skipped tests.

@taylorotwell taylorotwell merged commit 7c11613 into laravel:6.x Jan 15, 2020
2 checks passed
2 checks passed
continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@crynobone

This comment has been minimized.

Copy link
Contributor

crynobone commented Jan 15, 2020

Right now, there is no way to use a package's factories that are using models provided by the package itself. For testing the package and the application integration, it's easier to use the package's factories if there is any, instead of rewrite the factories.

If more than one factory registers factory model for the same model more than one, how does we control it now? Remember, with this it automatically declared and loaded now.

@iamgergo

This comment has been minimized.

Copy link
Contributor Author

iamgergo commented Jan 15, 2020

Yes, you can name your factory definitions.
However, the [default] will be the originally loaded factory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.