@@ -13,60 +13,62 @@ class RoutingTestCase extends MockeryTestCase
1313 use SupportsGlobalStubs;
1414 use SupportsScopedFixtures;
1515
16+ private $ originalFunctionsContent ;
17+ private $ functionsFile = '/roots/app/public/content/themes/sage/functions.php ' ;
18+ private $ routesFile = '/roots/app/public/content/themes/sage/routes/web.php ' ;
19+
1620 protected function setUp (): void
1721 {
1822 parent ::setUp ();
1923 $ this ->clearStubs ();
2024
21- // Ensure routes directory exists
22- if (! is_dir ('/roots/app/public/routes ' )) {
23- mkdir ('/roots/app/public/routes ' , 0777 , true );
25+ // Ensure Sage routes directory exists
26+ $ routesDir = dirname ($ this ->routesFile );
27+ if (! is_dir ($ routesDir )) {
28+ mkdir ($ routesDir , 0777 , true );
2429 }
2530
26- // Create web.php routes file
31+ // Create test routes file
2732 $ webRoutes = <<<'PHP'
2833<?php
2934
3035use Illuminate\Support\Facades\Route;
3136
32- Route::middleware(['web'])->group(function () {
33- Route::get('/test', fn() => 'Howdy')->name('test');
34- });
37+ Route::get('/test', fn() => 'Howdy')->name('test');
3538PHP;
3639
37- file_put_contents ('/roots/app/public/routes/web.php ' , $ webRoutes );
40+ file_put_contents ($ this ->routesFile , $ webRoutes );
41+
42+ // Backup original functions.php and add routing
43+ $ this ->originalFunctionsContent = file_get_contents ($ this ->functionsFile );
3844
39- // Ensure mu-plugins directory exists
40- if (! is_dir ('/roots/app/public/content/mu-plugins ' )) {
41- mkdir ('/roots/app/public/content/mu-plugins ' , 0777 , true );
45+ if (!str_contains ($ this ->originalFunctionsContent , 'withRouting ' )) {
46+ $ newContent = str_replace (
47+ '->boot(); ' ,
48+ '->withRouting(web: __DIR__ . \'/routes/web.php \') ' . "\n ->boot(); " ,
49+ $ this ->originalFunctionsContent
50+ );
51+ file_put_contents ($ this ->functionsFile , $ newContent );
4252 }
4353
44- // Create or update the Acorn boot mu-plugin
45- $ bootPlugin = <<<'PHP'
46- <?php
47- /*
48- Plugin Name: Acorn Boot
49- */
50-
51- use Roots\Acorn\Application;
52- use Roots\Acorn\Configuration\Exceptions;
53- use Roots\Acorn\Configuration\Middleware;
54-
55- add_action('after_setup_theme', function () {
56- Application::configure()
57- ->withMiddleware(function (Middleware $middleware) {
58- //
59- })
60- ->withExceptions(function (Exceptions $exceptions) {
61- //
62- })
63- ->withRouting(
64- web: '/roots/app/public/routes/web.php'
65- )
66- ->boot();
67- }, 0);
68- PHP;
54+ // Ensure Sage is the active theme
55+ if (function_exists ('switch_theme ' )) {
56+ switch_theme ('sage ' );
57+ }
58+ }
59+
60+ protected function tearDown (): void
61+ {
62+ // Restore original functions.php
63+ if ($ this ->originalFunctionsContent ) {
64+ file_put_contents ($ this ->functionsFile , $ this ->originalFunctionsContent );
65+ }
66+
67+ // Clean up test routes file
68+ if (file_exists ($ this ->routesFile )) {
69+ unlink ($ this ->routesFile );
70+ }
6971
70- file_put_contents ( ' /roots/app/public/content/mu-plugins/01-acorn-boot.php ' , $ bootPlugin );
72+ parent :: tearDown ( );
7173 }
7274}
0 commit comments