Laravel 12.38.0 Just Made Your Tests 2x Faster—Here’s How to Unlock It

Laravel 12.38.0 isn’t just another patch—it’s a quiet revolution for developers who care about speed, feedback loops, and CI efficiency. With two new traits designed to cache routes and config during test runs, your test suite can now run faster, leaner, and smarter.

Let’s break down what’s new, why it matters, and how to use it today.


⚡ What’s New in Laravel 12.38.0?

This release introduces:

  • WithCachedRoutes: Caches route definitions across your test suite
  • WithCachedConfig: Caches config loading across test runs
  • Interactive model:show: Prompts for missing input when no model is passed

These features are built for developers running large test suites, especially in CI pipelines or open-source packages.


🧪 Trait 1: WithCachedRoutes

🚨 Problem:

Every test run rebuilds your route definitions—even if they haven’t changed. This adds unnecessary boot time, especially in apps with hundreds of routes.

✅ Solution:

WithCachedRoutes caches your route definitions once per test session, eliminating redundant bootstrapping.

🧬 How to Use It (Pest):

use Illuminate\Foundation\Testing\WithCachedRoutes;

pest()->use(WithCachedRoutes::class);

🧬 How to Use It (PHPUnit):

use Illuminate\Foundation\Testing\WithCachedRoutes;

class ExampleTest extends TestCase
{
    use WithCachedRoutes;

    public function test_basic()
    {
        $this->get('/users')->assertOk();
    }
}

📈 Real-World Impact:

  • 10–30% faster test boot time in large apps
  • Ideal for route-heavy Laravel + Inertia or Laravel + Livewire projects
  • Works seamlessly with Pest’s global trait usage

🧪 Trait 2: WithCachedConfig

🚨 Problem:

Laravel loads config files fresh for every test—even if they’re static. This adds overhead and slows down test execution.

✅ Solution:

WithCachedConfig caches config loading across test runs, reducing boot time and memory usage.

🧬 How to Use It:

use Illuminate\Foundation\Testing\WithCachedConfig;

pest()->use(WithCachedConfig::class);

Or in PHPUnit:

use Illuminate\Foundation\Testing\WithCachedConfig;

class ConfigTest extends TestCase
{
    use WithCachedConfig;
}

⚠️ Caveat:

Only use this trait when your tests don’t mutate config values. If you’re testing config-driven behavior, skip this trait for those tests.


🧪 Bonus: Interactive model:show

Running php artisan model:show without arguments now prompts you to select a model interactively. No more guessing paths or typing long names—just pick from a list.

Perfect for exploring relationships, attributes, and structure in large codebases.


🧠 Why This Matters

These traits aren’t just syntactic sugar—they’re performance tools for serious devs:

  • CI pipelines → faster feedback loops
  • Open source packages → quicker contributor PR checks
  • Large test suites → less redundant bootstrapping
  • Pest users → plug-and-play speed boosts

If you’re running hundreds of tests daily, these traits can save minutes per run—and hours per week.


✅ Final Thoughts

Laravel 12.38.0 is a performance-focused release that rewards disciplined testing and scalable architecture. Whether you’re building SaaS tools, APIs, or open-source packages, these traits help you ship faster and test smarter.

Leave a Reply

Your email address will not be published. Required fields are marked *