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

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
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Tinkerwell logo

Tinkerwell

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

Tinkerwell
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
PhpStorm logo

PhpStorm

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

PhpStorm
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
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
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
Lucky Media logo

Lucky Media

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

Lucky Media
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

The latest

View all →
Filament v5.3.0 Released with Deferred Tab Badges and Column Manager Improvements image

Filament v5.3.0 Released with Deferred Tab Badges and Column Manager Improvements

Read article
Ward: A Security Scanner for Laravel image

Ward: A Security Scanner for Laravel

Read article
Kit: An Opinionated API Starter Kit for Laravel image

Kit: An Opinionated API Starter Kit for Laravel

Read article
Livewire v4.2.0 Released with Security Hardening and Laravel 13 Support image

Livewire v4.2.0 Released with Security Hardening and Laravel 13 Support

Read article
Filament through the years image

Filament through the years

Read article
Boost Guidelines & Skills Added in Inertia v2.3.16 image

Boost Guidelines & Skills Added in Inertia v2.3.16

Read article