Skip to content
New issue

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

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

Already on GitHub? # to your account

Allows custom factory #3

Merged
merged 3 commits into from
Aug 23, 2024
Merged

Allows custom factory #3

merged 3 commits into from
Aug 23, 2024

Conversation

edersoares
Copy link
Owner

Allows a custom factory to be used in testing.

use Illuminate\Database\Eloquent\Factories\Factory;

describe('Custom factory', function () {
    beforeEach()->eloquent(Post::class);

    // Customize the factory state
    beforeEach()->factory(fn (Factory $factory) => $factory->state([
        'title' => 'Laravel Tester',
    ]));

    // That will affect the result
    test()->toBeCreate()->assertDatabaseHas(Post::class, [
        'title' => 'Laravel Tester',
    ]);
});

Important to know that Laravel Tester use Model and Factory Discovery Conventions.

@edersoares edersoares merged commit badb914 into 2.x Aug 23, 2024
28 checks passed
@edersoares edersoares deleted the custom-factory branch August 23, 2024 20:18
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant