Skip to content

Bootstrap Foundation test applications through the kernel#426

Merged
binaryfire merged 5 commits into
0.4from
fix-pr-423-foundation-test-bootstrap
Jul 8, 2026
Merged

Bootstrap Foundation test applications through the kernel#426
binaryfire merged 5 commits into
0.4from
fix-pr-423-foundation-test-bootstrap

Conversation

@binaryfire

@binaryfire binaryfire commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

This fixes the base Foundation application test path.

A normal app test that extends Hypervel\Foundation\Testing\TestCase creates the application from bootstrap/app.php, then the framework test lifecycle immediately starts using framework services. The Hypervel port had kept the bootstrap/app.php require, but dropped Laravel's kernel bootstrap step. That leaves the app constructed but not bootstrapped, so facades, providers, and configuration are not ready when the test lifecycle touches them.

The fix is to put that missing bootstrap back where upstream has it: Foundation\Testing\TestCase::createApplication() now boots the created app through the console kernel before returning it.

This keeps the test path boring in the best way:

  • application tests use the same kernel-owned bootstrap sequence as the framework
  • HandleExceptions remains part of the normal bootstrap path
  • the HTTP and console kernels continue to own their own bootstrapper lists
  • Testbench keeps its separate package-test lifecycle
  • no test-specific bootstrapper constant is needed

I also removed the stale skeleton Tests\CreatesApplication trait. With the base Foundation test case doing the right thing, new app skeletons should not need to override createApplication() just to boot the framework.

The regression test creates a tiny temporary app, points APP_BASE_PATH at it, and runs the real Foundation\Testing\TestCase::setUp() path. It asserts that the app is bootstrapped, the base path is correct, facades are bound, and config is available. That covers the failure mode directly without involving Testbench's different lifecycle.

Credit to Richard's PR #423 for surfacing the bug and the app-test failure path.

Validation run locally:

  • ./vendor/bin/phpunit --no-progress tests/Foundation/Testing/ApplicationBootstrapTest.php
  • composer fix

Summary by CodeRabbit

  • Bug Fixes
    • Improved test application bootstrapping so the app is fully initialized before tests run.
    • Ensured the test base path and app config are picked up correctly during setup.
    • Added coverage for the application bootstrap flow to prevent regressions.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@binaryfire, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 20 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 71bb804c-8c28-4848-a40c-4044343e8730

📥 Commits

Reviewing files that changed from the base of the PR and between acbd2ff and fc02baf.

📒 Files selected for processing (5)
  • src/foundation/src/Application.php
  • src/foundation/src/Testing/TestCase.php
  • src/testbench/hypervel/tests/CreatesApplication.php
  • tests/Foundation/FoundationApplicationBuilderTest.php
  • tests/Foundation/Testing/ApplicationBootstrapTest.php
📝 Walkthrough

Walkthrough

The createApplication() method in TestCase now explicitly bootstraps the kernel via KernelContract before returning the application, rather than relying on the removed CreatesApplication trait's identical logic in the testbench package. A new test validates the bootstrap behavior.

Changes

TestCase Bootstrap Refactor

Layer / File(s) Summary
Explicit kernel bootstrap in createApplication
src/foundation/src/Testing/TestCase.php
Imports KernelContract and updates createApplication() to capture the app instance, explicitly call $app->make(KernelContract::class)->bootstrap(), then return $app; removes the now-redundant CreatesApplication trait from the testbench package.
Bootstrap behavior test
tests/Foundation/Testing/ApplicationBootstrapTest.php
Adds a test that scaffolds a temporary app directory with minimal bootstrap/config files, runs an anonymous FoundationTestCase, and asserts the application is bootstrapped with correct base path, config name, and facade identity, with cleanup in setUp/tearDown and a finally block.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Test as FoundationTestCase
  participant Bootstrap as bootstrap/app.php
  participant App as Application
  participant Kernel as KernelContract

  Test->>Bootstrap: require file
  Bootstrap-->>Test: return Application instance
  Test->>App: make(KernelContract::class)
  App-->>Kernel: resolve kernel
  Test->>Kernel: bootstrap()
  Kernel-->>Test: bootstrap complete
  Test->>Test: return bootstrapped $app
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: Foundation test applications are now bootstrapped through the console kernel.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-pr-423-foundation-test-bootstrap

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes the missing kernel bootstrap step in Foundation\Testing\TestCase::createApplication(), ensuring that facades, providers, and configuration are fully initialized before any test lifecycle method touches them. It also adds an Env repository fallback to Application::inferBasePath() so worker environments and test helpers can supply APP_BASE_PATH via putenv/setEnvironmentValue without writing to $_ENV.

  • TestCase::createApplication() now calls $app->make(KernelContract::class)->bootstrap() before returning the app, matching the lifecycle that the deleted CreatesApplication skeleton trait had been providing manually.
  • Application::inferBasePath() gains a third fallback (Env::get('APP_BASE_PATH')) between $_SERVER and the Composer loader, guarded with is_string() to handle the unset case; FoundationApplicationBuilderTest gains two new tests covering this path and switches teardown to unsetEnvironmentValue() so the Env repository cache is properly flushed.
  • A new ApplicationBootstrapTest builds a real temp app skeleton, exercises the full FoundationTestCase::setUp() path, and asserts bootstrapped state, correct base path, facade binding, and config availability — directly covering the failure mode this fix addresses.

Confidence Score: 5/5

Safe to merge — the change is a focused bug fix restoring one missing call, backed by a direct regression test.

The core change is a single-line addition that restores the kernel bootstrap step the codebase had always intended to run. The Env repository fallback is well-guarded with is_string(), teardown in both new and updated tests properly isolates process environment state, and the regression test exercises the exact failure path described in the PR.

No files require special attention.

Important Files Changed

Filename Overview
src/foundation/src/Testing/TestCase.php Added the missing kernel bootstrap step in createApplication() — now boots the app through KernelContract before returning it, matching the intended lifecycle.
src/foundation/src/Application.php Added Env repository as a third fallback (after $_ENV and $_SERVER) in inferBasePath(), with is_string() guard against null returns when the variable is unset.
tests/Foundation/Testing/ApplicationBootstrapTest.php New regression test that constructs a real temp app skeleton, runs the full FoundationTestCase setUp() lifecycle, and asserts the app is bootstrapped, facades are bound, and config is readable.
tests/Foundation/FoundationApplicationBuilderTest.php Two new tests cover the Env repository fallback path; tearDown updated to use unsetEnvironmentValue() to properly flush the Env repository cache after each test.
src/testbench/hypervel/tests/CreatesApplication.php Deleted — the trait duplicated what FoundationTestCase::createApplication() now does correctly; no consumers remain.

Reviews (3): Last reviewed commit: "test(testing): harden app bootstrap clea..." | Re-trigger Greptile

Comment thread tests/Foundation/Testing/ApplicationBootstrapTest.php Outdated
Restore the Laravel and Orchestra testing lifecycle for normal application tests by bootstrapping the created application through the console kernel inside Foundation\Testing\TestCase::createApplication().

The Hypervel port had kept the bootstrap/app.php require but dropped the kernel bootstrap call. That meant real app tests could construct an application object without running the bootstrappers, so the first facade access during the test lifecycle failed before user tests could run.

This uses the full kernel bootstrap path rather than a testing-specific bootstrapper list. There is no Hypervel-specific reason to diverge here: the kernel already owns the bootstrap sequence, HandleExceptions is part of the normal framework bootstrap, and the testing teardown already flushes exception state.

Also remove the temporary shared default bootstrapper constant introduced by the earlier PR draft and keep the HTTP and console bootstrapper lists local to their kernels, matching the framework shape used elsewhere.
Remove the stale skeleton CreatesApplication trait now that the base Foundation test case bootstraps applications directly.

Starter-style applications no longer need to carry this Laravel skeleton trait for Hypervel tests to work. Keeping it in the testbench skeleton would make the supported path harder to read because it suggests app tests should override createApplication(), when the framework test case now owns that boot path.
Add a regression test for the base Foundation testing path used by real applications.

The test creates a small temporary application fixture, points APP_BASE_PATH at it, and runs the real Foundation\Testing\TestCase setUp() lifecycle. That reproduces the path that previously failed before user tests could run, then asserts that the app is bootstrapped, the expected base path is used, facades are bound, and config is available.

The fixture is intentionally self-contained instead of copying the Testbench skeleton. Testbench owns a different lifecycle for package tests, while this coverage is specifically for application tests that rely on the base Foundation test case.
@binaryfire binaryfire force-pushed the fix-pr-423-foundation-test-bootstrap branch from acbd2ff to 97e584c Compare July 8, 2026 07:50
Teach Application::inferBasePath() to fall back to the Env repository after checking the explicit APP_BASE_PATH superglobals.

This keeps the existing precedence for raw  and  values while making framework test helpers and worker environments that write through putenv visible to base path inference. The Env lookup is evaluated lazily so the repository is not touched when an explicit superglobal value is present.

Add builder coverage for APP_BASE_PATH values set through the environment repository and for  taking precedence over that fallback. While the builder test file is touched, align its test methods with the current : void convention.
Move APP_BASE_PATH restoration and facade reset for the Foundation app bootstrap regression test into the outer test lifecycle.

The anonymous inner Foundation test case still tears itself down inside the test method, but process-global cleanup now runs from the enclosing test tearDown. That means facade state and APP_BASE_PATH are restored even when the inner teardown throws, avoiding cross-test contamination in a long-running parallel worker.

This directly addresses Greptile's review comment without weakening the regression coverage for the real application test bootstrap path.
@binaryfire binaryfire merged commit 089ae0b into 0.4 Jul 8, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant