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

Specifying a specific seeder on base test class does not apply when using in-memory Sqlite DB #41863

Closed
cicnavi opened this issue Apr 7, 2022 · 9 comments · Fixed by #41869
Closed
Labels

Comments

@cicnavi
Copy link

cicnavi commented Apr 7, 2022

  • Laravel Version: 8.76.0
  • PHP Version: 7.3.25
  • Database Driver & Version: in-memory Sqlite

Description:

According the docs for seeding while testing, we can specify a specific seeder on the base test class which would then be ran instead of the default Database\Seeders\DatabaseSeeder class. This does not work if in-memory SQLite DB is used.

My first thought is that this is because artisan migrate command does not accept seed class parameter (used here

$this->artisan('migrate', $this->migrateUsing());
),
while artisan migrate:fresh command does (used here
$this->artisan('migrate:fresh', $this->migrateFreshUsing());
)

Is there a reason for not running aditional artisan db:seed command in \Illuminate\Foundation\Testing\RefreshDatabase::refreshInMemoryDatabase() method instead of seeding it using artisan migrate (if seeding is enabled and specific seeder is set on base test class)?

To address this I simply seed with specific seeder on my test class using $this->seed('SpecificSeeder') method.

The problem was mentioned here, however it was not addressed further.

Thank you for your valuable work...

Steps To Reproduce:

Set a specific seeder class in base test class while using in-memory Sqlite DB.

@driesvints
Copy link
Member

Heya, thanks for reporting.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as separate commits on the main/master branch and share the repository here? Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Please do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@cicnavi
Copy link
Author

cicnavi commented Apr 7, 2022

Hi, here is the repo:

https://github.com/cicnavi/bug-report

with one commit https://github.com/cicnavi/bug-report/commit/023154160801cb15a67fd65f54d4b9fd6973db1e

As per docs, I have added a $seeder prop in \Tests\TestCase which points to custom seeder \Database\Seeders\TestDatabaseSeeder.

The test \Tests\Feature\SeedingUsingCustomSeederTest::testSampleFromTestSeederExists fails because it expects a Sample in DB which should have been seeded from custom seeder \Database\Seeders\TestDatabaseSeeder instead of default \Database\Seeders\DatabaseSeeder (as per docs).

@driesvints
Copy link
Member

@cicnavi your test contains test as a value while your seeder contains default.

@driesvints
Copy link
Member

Sorry, I misread that. You're correct, this seems broken right now.

@cicnavi
Copy link
Author

cicnavi commented Apr 7, 2022

Thanks for getting back to it...

@driesvints
Copy link
Member

I managed to write a fix for this. Please check and test #41869. I managed to get your test passing with it.

@driesvints driesvints linked a pull request Apr 7, 2022 that will close this issue
@cicnavi
Copy link
Author

cicnavi commented Apr 7, 2022

That was quick... Tried it out on a real project and works as expected.
I hope it will also be fixed in v9.*...
Thanks and best regards

@driesvints
Copy link
Member

@cicnavi yeah bug fixes are merged upstream so it'll land in 9.x as well if it gets merged.

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

Successfully merging a pull request may close this issue.

2 participants