-
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add Laravel Testbench-style testing features #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
binaryfire
wants to merge
18
commits into
hypervel:main
Choose a base branch
from
binaryfire:feat/testbench-testing-features
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add Laravel Testbench-style testing features #344
binaryfire
wants to merge
18
commits into
hypervel:main
from
binaryfire:feat/testbench-testing-features
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Phase 1: defineEnvironment hook - Add defineEnvironment($app) call in refreshApplication() before app boot - Add empty defineEnvironment() method for subclass override - Add DefineEnvironmentTest Phase 2: Attribute contracts - TestingFeature: marker interface - Resolvable: resolve() for meta-attributes (does NOT extend TestingFeature) - Actionable: handle($app, Closure $action) - Invokable: __invoke($app) - BeforeEach/AfterEach: per-test lifecycle hooks - BeforeAll/AfterAll: per-class lifecycle hooks Phase 3: AttributeParser and FeaturesCollection - AttributeParser: parses class/method attributes with inheritance and Resolvable support - FeaturesCollection: collection for deferred attribute callbacks Phase 4.2: HandlesAttributes trait - parseTestMethodAttributes() for executing attribute callbacks
- Static caching for class/method attributes - usesTestingConcern() to check trait usage - usesTestingFeature() for programmatic attribute registration - resolvePhpUnitAttributes() merges all attribute sources - Lifecycle methods: setUpTheTestEnvironmentUsingTestCase, tearDownTheTestEnvironmentUsingTestCase, setUpBeforeClassUsingTestCase, tearDownAfterClassUsingTestCase
Simplified orchestrator for default + attribute flows. Uses inline flag-based memoization instead of Orchestra's once() helper. No annotation/pest support - not needed for Hypervel.
- DefineEnvironment: calls test method with $app - WithConfig: sets config value directly - DefineRoute: calls test method with $router - DefineDatabase: deferred execution, resets RefreshDatabaseState - ResetRefreshDatabaseState: resets database state before/after all tests - WithMigration: loads explicit migration paths - RequiresEnv: skips test if env var missing - Define: meta-attribute resolving to env/db/route attributes
…rastructure - Change Actionable::handle() implementations to return mixed instead of void - Change Invokable::__invoke() implementations to return mixed instead of void - Fix TestingFeature orchestrator closure return type - Add @phpstan-ignore for rescue callback type resolution - Update setUpTheTestEnvironmentUsingTestCase() to execute all attribute types (Invokable, Actionable, BeforeEach)
- Call setUpApplicationRoutes() automatically in afterApplicationCreated - Add reflection check to skip empty web routes group registration - Refactor Sanctum tests to use new testbench pattern (getPackageProviders, defineEnvironment, defineRoutes) - Add tests for route accessibility and routing without defineWebRoutes
…ritance - Mark parseTestMethodAttributes() as @internal to prevent misuse - Add test verifying Define meta-attribute is resolved by AttributeParser - Add test verifying Define meta-attribute is executed through lifecycle - Add tests verifying attributes are inherited from parent TestCase classes
Add proper type hints following existing codebase conventions: - Use `ApplicationContract` alias for contract type hints - Use `Router` type hints for route definition methods - Update all contracts, attributes, traits, and test files This improves type safety while maintaining consistency with the existing codebase pattern where 20+ files use the ApplicationContract alias convention.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR ports Laravel Orchestral Testbench's testing infrastructure to Hypervel, bringing familiar testing patterns and PHP 8 attribute-based test configuration to Hypervel.
Key Features Ported from Laravel Testbench
defineEnvironment()hook - Pre-boot application configuration, matching Laravel'sdefineEnvironment()patterngetPackageProviders()andgetPackageAliases()methods for package testingdefineRoutes()anddefineWebRoutes()with automatic web middleware group wrappingdefineDatabaseMigrations(),destroyDatabaseMigrations(),defineDatabaseSeeders()Testing Attributes (Following Laravel Testbench Patterns)
#[WithConfig('key', 'value')]#[DefineEnvironment('methodName')]$appfor environment setup#[DefineRoute('methodName')]$routerfor route definition#[DefineDatabase('methodName')]#[WithMigration('path')]#[RequiresEnv('VAR')]#[ResetRefreshDatabaseState]#[Define('group', 'method')]Lifecycle Hooks (Matching Laravel Testbench)
BeforeAll/AfterAll- Class-level lifecycle (static, runs once per test class)BeforeEach/AfterEach- Test-level lifecycle (runs for each test method)Invokable- Direct invocation with app instanceActionable- Method delegation with closure callbackHypervel-Specific Adaptations
While following Laravel Testbench patterns closely, this implementation includes Hypervel-specific adaptations:
BeforeEach/AfterEachattributes execute insiderunInCoroutine(), matching wheresetUpTraits()runs in Foundation TestCase$router->group()signaturesetUpApplicationRoutes()is called automatically inafterApplicationCreated, so routes defined viadefineRoutes()are available without manual setupRouteFileCollectorwhendefineWebRoutes()isn't overriddenExample Usage
Files Changed
New Files (28)
Foundation Contracts (
src/foundation/src/Testing/Contracts/Attributes/):TestingFeature.php,Resolvable.php,Actionable.php,Invokable.phpBeforeEach.php,AfterEach.php,BeforeAll.php,AfterAll.phpFoundation Attributes (
src/foundation/src/Testing/Attributes/):DefineEnvironment.php,WithConfig.php,DefineRoute.php,DefineDatabase.phpWithMigration.php,RequiresEnv.php,ResetRefreshDatabaseState.php,Define.phpFoundation Infrastructure (
src/foundation/src/Testing/):AttributeParser.php- Parses class/method attributes with Resolvable supportConcerns/HandlesAttributes.php- Attribute parsing traitConcerns/InteractsWithTestCase.php- Caching and lifecycle executionFeatures/TestingFeature.php- Orchestrator for default + attribute flowsFeatures/FeaturesCollection.php- Collection for deferred callbacksTestbench Traits (
src/testbench/src/Concerns/):CreatesApplication.php- Package providers/aliasesHandlesRoutes.php- Route definition helpersHandlesDatabases.php- Database migration helpersTests (7 test files with comprehensive coverage)
Modified Files (3)
src/foundation/src/Testing/Concerns/InteractsWithContainer.php- AddeddefineEnvironment()hooksrc/testbench/src/TestCase.php- Integrated new traits with coroutine-aware lifecycletests/Sanctum/AuthenticateRequestsTest.php- Refactored to use new testbench pattern (getPackageProviders,defineEnvironment,defineRoutes)