Skip to content

Commit 4d6db5c

Browse files
retlehsclaude
andcommitted
♻️ Update routing tests to work with Sage theme
- Refactor routing tests from mu-plugin approach to Sage theme integration - Add proper backup/restore of Sage functions.php with cleanup in tearDown - Add COMPOSER_ROOT_VERSION env var to handle version constraints cleanly - Update GitHub Actions to test with Sage theme activation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bc0f661 commit 4d6db5c

File tree

6 files changed

+57
-52
lines changed

6 files changed

+57
-52
lines changed

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
XDEBUG_MODE: '${XDEBUG_MODE:-develop,debug}'
1414
XDEBUG_CONFIG: '${XDEBUG_CONFIG:-client_port=9003 client_host=host.docker.internal discover_client_host=true}'
1515
REPOSITORY_URL: '${REPOSITORY_URL:-https://github.com/roots/bedrock.git}'
16+
COMPOSER_ROOT_VERSION: '5.0.x-dev'
1617
volumes:
1718
- ~/.ssh:/home/vscode/.ssh:ro
1819
- 'app:/roots/app'

.devcontainer/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ sudo chmod g+w -R /roots/app
102102
cd /roots
103103

104104
# wp-cli.yml file
105-
cat <<WPCLI > /roots/wp-cli.yml
105+
sudo tee /roots/wp-cli.yml > /dev/null <<WPCLI
106106
path: /roots/app/public/wp
107107
server:
108108
docroot: /roots/app/public

.devcontainer/setup.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ fi
3636
wp db reset --yes
3737
wp core install --url="${WP_HOME}" --title="${WP_SITE_TITLE}" --admin_user="admin" --admin_email="admin@roots.test" --admin_password="password" --skip-email
3838

39-
# Add sage if there are no themes
40-
if [ ! "$(ls -d $(wp theme path --skip-plugins --skip-themes 2>/dev/null)/*/)" ]; then
41-
composer require -d /roots/app roots/sage
39+
# Add sage if it's not active
40+
if ! wp theme status sage --skip-plugins --skip-themes 2>/dev/null | grep -q "^sage.*active"; then
41+
cd /roots/app
42+
# Only require sage if it doesn't exist
43+
if ! wp theme is-installed sage --skip-plugins --skip-themes 2>/dev/null; then
44+
composer require roots/sage -W
45+
fi
4246
wp theme activate sage
4347
# Build the Sage theme
4448
cd $(wp theme path --skip-plugins --skip-themes 2>/dev/null)/sage

.github/workflows/integration.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ jobs:
1717
with:
1818
configFile: .devcontainer/devcontainer.json
1919
runCmd: |
20-
cd /roots/app
21-
composer install
22-
# ???
23-
composer remove roots/acorn
24-
composer require roots/acorn --no-interaction
25-
composer require --dev nunomaduro/collision
26-
composer require --dev spatie/laravel-ignition
27-
# ???
20+
# Wait for database to be ready
2821
while ! mysqladmin ping -h"database" --silent; do
2922
sleep 1
3023
done
31-
wp core install --url=http://web:8080 --title=Acorn --admin_user=admin --admin_password=admin --admin_email=admin@example.com --skip-email --allow-root
24+
# Ensure WordPress is installed
25+
cd /roots/app
26+
wp core install --url=http://web:8080 --title="Acorn Testing" --admin_user=admin --admin_password=password --admin_email=admin@roots.test --skip-email --allow-root
27+
# Ensure Sage theme is activated
28+
wp theme activate sage
29+
# Clear optimization cache
3230
wp acorn optimize:clear
33-
31+
# Run the routing integration tests
3432
cd /roots/acorn
3533
composer install
3634
composer run-script test tests/Integration/Routing

tests/Integration/Routing/RoutingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
$response = $client->request('GET', 'http://web:8080/non-existent-'.time());
4545
expect($response->getStatusCode())->toBe(404);
46-
expect((string) $response->getBody())->toContain('Page not found');
46+
expect((string) $response->getBody())->toContain('Not Found');
4747
expect((string) $response->getBody())->toHaveBodyClass('error404');
4848
});
4949

tests/Integration/Routing/RoutingTestCase.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3035
use 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');
3538
PHP;
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

Comments
 (0)