@@ -13,60 +13,62 @@ class RoutingTestCase extends MockeryTestCase
13
13
use SupportsGlobalStubs;
14
14
use SupportsScopedFixtures;
15
15
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
+
16
20
protected function setUp (): void
17
21
{
18
22
parent ::setUp ();
19
23
$ this ->clearStubs ();
20
24
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 );
24
29
}
25
30
26
- // Create web.php routes file
31
+ // Create test routes file
27
32
$ webRoutes = <<<'PHP'
28
33
<?php
29
34
30
35
use Illuminate\Support\Facades\Route;
31
36
32
- Route::middleware(['web'])->group(function () {
33
- Route::get('/test', fn() => 'Howdy')->name('test');
34
- });
37
+ Route::get('/test', fn() => 'Howdy')->name('test');
35
38
PHP;
36
39
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 );
38
44
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 );
42
52
}
43
53
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
+ }
69
71
70
- file_put_contents ( ' /roots/app/public/content/mu-plugins/01-acorn-boot.php ' , $ bootPlugin );
72
+ parent :: tearDown ( );
71
73
}
72
74
}
0 commit comments