Replies: 10 comments
-
How are your tests refreshing the database? Are you just using #53997 will only affect your test suite runtime if your tests are committing the transaction started by |
Beta Was this translation helpful? Give feedback.
-
I am just using the After the slowdown I investigated solutions for speeding up test suites which recommended adding transactions for setting up data in tests. For example; public function createMusic(): void
{
DB::beginTransaction();
Listen::factory()->count(20)->enabled()->recent()->create();
Track::factory()->count(5)->withListens()->enabled()->create();
Artist::factory()->count(5)->enabled()->create();
DB::commit();
} |
Beta Was this translation helpful? Give feedback.
-
Are you maybe calling something like Also, I've the |
Beta Was this translation helpful? Give feedback.
-
Yes, similar to public function resetMusic(): void
{
Schema::disableForeignKeyConstraints();
DB::beginTransaction();
User::query()->truncate();
Listen::query()->truncate();
Track::query()->truncate();
Artist::query()->truncate();
Album::query()->truncate();
AlbumTrack::query()->truncate();
DB::commit();
Schema::enableForeignKeyConstraints();
} |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what you mean by "to keep everything consistent". It looks like you're manually resetting the database, but that's what I think you can remove your For more explanation, calling |
Beta Was this translation helpful? Give feedback.
-
I updated all the Running the tests with the |
Beta Was this translation helpful? Give feedback.
-
If your tests are still slower than before after changing those |
Beta Was this translation helpful? Give feedback.
-
Changing to I do have a couple of migrations which use DB::statement("
ALTER TABLE `thing`
MODIFY COLUMN `type` ENUM('person', 'pet', 'bike', 'thing', 'place')
DEFAULT 'thing'
"); |
Beta Was this translation helpful? Give feedback.
-
It sounds like some of your tests depend on the database table's auto-increment starting at 1. This normally doesn't work when you use Truncating tables causes the I don't really have a solution for you except for not using |
Beta Was this translation helpful? Give feedback.
-
I am not using "hard-coded auto-increment" values… I am having issues with duplicate keys. I would need to spend a lot more time researching these specific tests and running them without the From my initial tests, when I use |
Beta Was this translation helpful? Give feedback.
-
Laravel Version
11.37
PHP Version
8.2.26
Database Driver & Version
No response
Description
My test suite using PHPUnit changed from taking ~10 minutes to over 25 minutes.
I think it could be related to this change; #53997
Steps To Reproduce
Run a large PHPUnit test suite using v11.36.1 and then compare the runtime when running the same test suite using v11.37.
Beta Was this translation helpful? Give feedback.
All reactions