Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Cache Routes and Config During Testing in Laravel 12.38

Last updated on by

Cache Routes and Config During Testing in Laravel 12.38 image

Never Miss a Laravel Release 🚀

Sign up and get an email with each new Laravel release

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.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

image
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
SerpApi logo

SerpApi

Access real-time search engine results through a simple API—no more scraping headaches! Use it for AI applications, SEO tools, product research, travel information, and more

SerpApi
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media

The latest

View all →
Attach Addresses to Any Eloquent Model with Laravel Addressable image

Attach Addresses to Any Eloquent Model with Laravel Addressable

Read article
Generate Livewire Skeleton Placeholders Automatically with Wirebones image

Generate Livewire Skeleton Placeholders Automatically with Wirebones

Read article
Laravel ClickHouse: A Full-Featured ClickHouse Driver for Laravel image

Laravel ClickHouse: A Full-Featured ClickHouse Driver for Laravel

Read article
Laravel Installer Now Returns JSON When Running Inside an AI Agent image

Laravel Installer Now Returns JSON When Running Inside an AI Agent

Read article
Queue-Wide Inspection Methods in Laravel 13.8.0 image

Queue-Wide Inspection Methods in Laravel 13.8.0

Read article
Verifiable Audit Logging with Laravel Chronicle image

Verifiable Audit Logging with Laravel Chronicle

Read article