Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zufflie's avatar

Laracel Tests with Pest extremely slow suddenly

Hey guys,

So i have a pretty big Project i manage, Deadlines coming to an end in February. I used Pest Driven Approach and this worked fine until maybe a week ago, i do now know what changed but suddenly my ' abit' more complex tests run for 49 Seconds 1 Minute + were it were before maybe 7 seconds.

I use Laravel 11, Herd, Pest, Php 8.4 have no Plugins for PHP enabled in the Ini, disabled Coverage Plugins.. I do now know what to do honestly, i checked all i could check but it just became painfully slow to the point where i can't test anything anymore besides Arch Tests and some very Basic DTO Stuff.

for example this test:

it('generates a new invite link for a new user', function () {
    // Arrange
    $newEmail = '[email protected]';
    $talent = asTalent()->userable;
    // Act
    $inviteLink = $talent->generateInviteLink($newEmail);
    // Assert
    $this->assertStringContainsString(route('talent.registration.invitation'), $inviteLink);
    $this->assertStringContainsString('email='.urlencode($newEmail), $inviteLink); // Use URL-encoded email
    $this->assertStringContainsString("userId={$talent->user->id}", $inviteLink);
});

run for over 2 Minutes.. I mean its just a URL generation thing..

Anybody any ideas? :D

0 likes
2 replies
LaryAI's avatar
Level 58

When tests suddenly become slow, especially in a Laravel project using Pest, there are several potential causes and solutions you can explore:

  1. Database Transactions: Ensure that your tests are using database transactions correctly. If transactions are not being rolled back properly, it can lead to a buildup of data, which slows down subsequent tests. Make sure you are using use DatabaseTransactions or use RefreshDatabase in your test setup.

  2. Caching Issues: Clear any caches that might be affecting your tests. Run the following commands to clear various caches:

    php artisan cache:clear
    php artisan config:clear
    php artisan route:clear
    php artisan view:clear
    
  3. Environment Configuration: Double-check your .env.testing file to ensure that it is configured correctly. Make sure you are using an in-memory SQLite database for testing if possible, as it is much faster than other database drivers.

  4. Dependencies and Updates: Check if any recent updates to your dependencies might be causing the slowdown. You can review your composer.json and composer.lock files for any recent changes. Consider rolling back to a previous version if necessary.

  5. Performance Profiling: Use a profiler to identify bottlenecks in your tests. Tools like Blackfire or Xdebug can help you pinpoint where the slowdown is occurring.

  6. Optimize Test Code: Review your test code for any inefficiencies. For example, ensure that you are not making unnecessary database queries or API calls within your tests.

  7. Check for External Services: If your tests rely on external services, ensure that they are not causing delays. Consider mocking these services if possible.

  8. Pest Configuration: Review your Pest configuration to ensure that no unnecessary plugins or settings are enabled that could be affecting performance.

  9. PHP Configuration: Ensure that your PHP configuration is optimized for performance. Check your php.ini settings for any anomalies.

  10. Hardware and Environment: If you are running tests on a local machine, ensure that your hardware resources are not being maxed out by other processes. Consider running tests on a dedicated CI server if possible.

By systematically going through these potential issues, you should be able to identify the cause of the slowdown and address it accordingly. If the problem persists, consider reaching out to the community with specific details about any changes made recently to your project or environment.

zufflie's avatar

I spent 2 days with this and as i wrote this post i figured out..

For Business-Purposes i had built a seeder for a vast amount of different jobs, skills etc and i forgot to actually comment this out.. Thanks all :D

Please or to participate in this conversation.