traitsUsedByTest = class_uses_recursive(static::class); if ($app->configurationIsCached()) { throw new RuntimeException('Tests refuse cached configuration. Remove the test config cache before retrying.'); } // Validate before providers boot or RefreshDatabase can run migrations. $app->afterBootstrapping(LoadConfiguration::class, function (Application $app): void { if (! $app->environment('testing')) { throw new RuntimeException('Tests require APP_ENV=testing.'); } InMemoryConnectionFactory::assertSafe((array) $app['config']->get( 'database.connections.'.$app['config']->get('database.default') )); }); // Also guard named/dynamic connections and changes made by individual tests. $app->extend('db.factory', fn () => new InMemoryConnectionFactory($app)); $app->make(Kernel::class)->bootstrap(); return $app; } }