News

Cache Routes and Config During Testing in Laravel 12.38

Published
Cache Routes and Config During Testing in Laravel 12.38 image

Release updates

Never miss a Laravel release

Get an email whenever a new Laravel release lands.

The Laravel team released version 12.38.0, adding a WithCachedRoutes test trait, a WithCachedConfig test trait, a model prompt for the model:show command, and more.

WithCachedRoutes Testing Trait

Luke Kuzmish contributed the WithCachedRoutes trait, which builds routes once and stores them in memory. Routes are only built once for all tests in your test suite:

use App\Http\Controllers\UserController;
use Illuminate\Foundation\Testing\WithCachedRoutes;
use Tests\TestCase;

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

test('basic example', function () {
    $this->get(action([UserController::class, 'index']));

    // ...
});

// PHPUnit
class BasicTest extends TestCase
{
    use WithCachedRoutes;

    /**
     * A basic functional test example.
     */
    public function test_basic_example(): void
    {
        $response = $this->get(action([UserController::class, 'index']));

        // ...
    }
}

See Pull Request #57623 for more info.

WithCachedConfig Testing Trait

Luke Kuzmish contributed a WithCachedConfig trait, which builds the configuration in your app once and reuses it for all tests:

use Illuminate\Foundation\Testing\WithCachedConfig;
use Tests\TestCase;

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

test('modifies config', function () {
    config(['services.postmark.key' => 'xyz']);
    expect(config('services.postmark.key'))->toBe('xyz');
});

test('uses default config', function () {
    expect(config('services.postmark.key'))->not->toBe('xyz');
});

// PHPUnit
class ConfigTest extends TestCase
{
    use WithCachedConfig;

    /**
     * A test that modifies the config.
     */
    public function test_modifies_config(): void
    {
        $this->assertEquals('xyz', config('services.postmark.key'));
    }

    /**
     * A test that makes no modification to the config.
     */
    public function test_uses_default_config(): void
    {
        $this->assertNotEquals('xyz', config('services.postmark.key'));
    }
}

See Pull Request #57663 for more info.

The model:show Command Now Prompts for Input

Razin Shaikh contributed an update to the model:show command to prompt for input when you run the command without arguments. Here's a before-and-after example:

Before Laravel 12.38
Before Laravel 12.38
Starting in Laravel 12.38+
Starting in Laravel 12.38+

See Pull Request #57671 for more info.

Release notes

You can see the complete list of new features and updates below and the diff between 12.37.0 and 12.38.0 on GitHub. The following release notes are directly from the changelog:

v12.38.0

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
Email Sending and Testing for Laravel in One Account image

Email Sending and Testing for Laravel in One Account

Read article
Decide with Jev: Tie Every AI Check to the Exact Draft image

Decide with Jev: Tie Every AI Check to the Exact Draft

Read article
PIE 1.5 Changes PHP Extension Installs in CI image

PIE 1.5 Changes PHP Extension Installs in CI

Read article
Delete Expired Sessions in Laravel With a Scheduled Command image

Delete Expired Sessions in Laravel With a Scheduled Command

Read article
Pollora: Run WordPress Inside a Laravel Application image

Pollora: Run WordPress Inside a Laravel Application

Read article
Scheduled Session Garbage Collection in Laravel 13.39 image

Scheduled Session Garbage Collection in Laravel 13.39

Read article