Testing
trait Testing
Composes the Testbench testing concerns into a single upstream-facing trait.
Hypervel's base testing lifecycle already owns application refresh and callback execution, so this trait primarily restores the upstream public surface and concern grouping.
Traits
Creates and bootstraps the application for testbench tests.
Handles parsing and executing test method attributes.
Provides per-worker database isolation for parallel testing.
Properties
| static protected array<class-string, array<class-string, class-string>> | $cachedTestCaseUses | Cached traits used by each test case class. |
from InteractsWithTestCase |
| static protected array<int, array{key: class-string, instance: object}> | $testCaseTestingFeatures | Programmatically added class-level testing features. |
from InteractsWithTestCase |
| static protected array<int, array{key: class-string, instance: object}> | $testCaseMethodTestingFeatures | Programmatically added method-level testing features. |
from InteractsWithTestCase |
| protected null|Closure): void | $testCaseSetUpCallback | The cached test case setUp resolver. |
from InteractsWithPHPUnit |
| protected null|Closure): void | $testCaseTearDownCallback | The cached test case tearDown resolver. |
from InteractsWithPHPUnit |
| static protected array<string, array<int, array{key: class-string, instance: object}>> | $cachedTestCaseClassAttributes | Cached class attributes by class name. |
from InteractsWithPHPUnit |
| static protected array<string, array<int, array{key: class-string, instance: object}>> | $cachedTestCaseMethodAttributes | Cached method attributes by "class:method" key. |
from InteractsWithPHPUnit |
| null|Application | $app | from InteractsWithPHPUnit | |
| protected string|false|null | $applicationBootstrapFile | The resolved application bootstrap file. |
from WithHypervelBootstrapFile |
| null|bool | $enablesPackageDiscoveries | from CreatesApplication | |
| null|bool | $loadEnvironmentVariables | from CreatesApplication | |
| protected bool | $syncTestbenchRoutesHasRun | Whether Testbench routes have been synchronized for this test. |
from HandlesRoutes |
| protected bool | $testbenchRouteCleanupRegistered | Whether route file cleanup has been registered for this test. |
from HandlesRoutes |
| protected bool | $reloadingApplicationForCachedRoutes | Whether defineCacheRoutes() is reloading the application to load cached routes. |
from HandlesRoutes |
| protected array<int, string> | $testbenchRouteFiles | Route files written by this test instance. |
from HandlesRoutes |
| protected MigrateProcessor> | $cachedTestMigratorProcessors | List of cached migrators instances. |
from InteractsWithMigrations |
Methods
Rewrite the default connection's database name for parallel testing.
Ensure the per-worker database exists, creating it if needed.
Determine if the database should be managed for parallel testing.
Get the per-worker test database name.
Determine if the test case uses the given trait, or the Testing trait by default.
Determine if the test case uses refresh-database testing concerns.
Cache and return traits used by test case.
Programmatically add a testing feature attribute.
Resolve PHPUnit method attributes for specific method.
Execute BeforeEach lifecycle attributes.
Execute AfterEach lifecycle attributes.
Load test fixtures and execute BeforeAll lifecycle attributes.
Execute AfterAll lifecycle attributes and clear caches.
Determine if the object is running as a PHPUnit test case.
Resolve the PHPUnit test class name.
Resolve the PHPUnit test method name.
Resolve and cache PHPUnit attributes for current test.
Cache uses for test case before class runs.
Clear PHPUnit caches after class teardown.
Determine if the trait is used within testing using Pest.
Determine if the object implements Pest test runner.
Get Application's base path.
Ignore package discovery from.
Resolve application Console Kernel implementation.
Get application HTTP Kernel implementation using Workbench.
Get application HTTP exception handler using Workbench.
Get the cached Workbench configuration.
Get application bootstrap file path (if exists).
Determine if application is using a custom application kernels.
Determine if application is bootstrapped using Testbench's default skeleton.
Create the default application implementation.
Make a relative COMPOSER_VENDOR_DIR from the application environment absolute.
Mask inherited framework APP_ENV for Testbench applications that opt out of loading env files.
Determine if the current test explicitly configured an environment variable.
Resolve application console kernel implementation.
Load configuration and register package providers/aliases.
Resolve the route provider from application provider overrides.
Run bootstrappers individually with defineEnvironment() inserted.
Refresh route name lookups now and whenever the URL generator is resolved.
Configure worker-specific cache paths for parallel testing.
Get the current ParaTest worker token before the application exists.
Terminate and flush an application, returning any cleanup failure.
Mark the test as skipped when condition is not equivalent to true.
Mark the test as skipped when condition is equivalent to true.
Parse and execute test method attributes of a specific type.
Determine if using in-memory SQLite database connection.
Define database migrations after database refreshed.
Register cleanup for route files and route cache written by this test.
Get a route file path owned by this test instance.
Define hooks to migrate the database before and after each test.
Determine whether migration paths should be registered for an upcoming migration.
Resolve Package Migrations Artisan command options.
Migrate Hypervel's default migrations.
Migrate all Hypervel migrations.
Resolve Hypervel Migrations Artisan command options.
Run and retain a migration processor for teardown.
Determine whether the active database concerns retain in-memory state.
Reload the application instance.
Details
in
InteractsWithParallelDatabase at line 43
protected void
configureParallelDatabaseName(mixed $app)
Rewrite the default connection's database name for parallel testing.
Config-only — does not create connections or purge pools. Called early in CreatesApplication (after config is loaded, before defineEnvironment) so that custom connections derived from the default connection inherit the per-worker database name.
No-op when not running in parallel or when using in-memory SQLite.
in
InteractsWithParallelDatabase at line 97
protected void
ensureParallelDatabaseExists()
Ensure the per-worker database exists, creating it if needed.
Called before Testbench database requirements and from database testing traits (RefreshDatabase, DatabaseMigrations, DatabaseTruncation, DatabaseTransactions) after the app is booted and connections are available. The config has already been rewritten by configureParallelDatabaseName().
No-op when not running in parallel or when using in-memory SQLite.
in
InteractsWithParallelDatabase at line 160
protected bool
shouldManageParallelDatabase(mixed $driver, string $database)
Determine if the database should be managed for parallel testing.
in
InteractsWithParallelDatabase at line 187
protected string
parallelTestDatabase(string $database, string $token)
Get the per-worker test database name.
in
InteractsWithTestCase at line 54
static bool
usesTestingConcern(string|null $trait = null)
Determine if the test case uses the given trait, or the Testing trait by default.
in
InteractsWithTestCase at line 62
static bool
usesRefreshDatabaseTestingConcern()
Determine if the test case uses refresh-database testing concerns.
in
InteractsWithTestCase at line 75
static array
cachedUsesForTestCase()
| internal |
Cache and return traits used by test case.
in
InteractsWithTestCase at line 89
static void
usesTestingFeature(object $attribute, int $flag = Attribute::TARGET_CLASS)
Programmatically add a testing feature attribute.
in
InteractsWithTestCase at line 120
abstract static protected Collection
resolvePhpUnitAttributesForMethod(string $className, string|null $methodName = null)
Resolve PHPUnit method attributes for specific method.
in
InteractsWithTestCase at line 127
protected void
setUpTheTestEnvironmentUsingTestCase()
| internal |
Execute BeforeEach lifecycle attributes.
in
InteractsWithTestCase at line 142
protected void
tearDownTheTestEnvironmentUsingTestCase()
| internal |
Execute AfterEach lifecycle attributes.
in
InteractsWithTestCase at line 178
static void
setUpBeforeClassUsingTestCase()
| internal |
Load test fixtures and execute BeforeAll lifecycle attributes.
in
InteractsWithTestCase at line 195
static void
tearDownAfterClassUsingTestCase()
| internal |
Execute AfterAll lifecycle attributes and clear caches.
in
InteractsWithPHPUnit at line 56
bool
isRunningTestCase()
Determine if the object is running as a PHPUnit test case.
in
InteractsWithPHPUnit at line 68
string|null
resolvePhpUnitTestClassName()
| internal |
Resolve the PHPUnit test class name.
in
InteractsWithPHPUnit at line 84
string|null
resolvePhpUnitTestMethodName()
| internal |
Resolve the PHPUnit test method name.
in
InteractsWithPHPUnit at line 100
protected Collection
resolvePhpUnitAttributes()
| internal |
Resolve and cache PHPUnit attributes for current test.
in
InteractsWithPHPUnit at line 146
void
setUpTheEnvironmentUsing(Closure $setUp)
| internal |
Define the setUp environment using callback.
in
InteractsWithPHPUnit at line 158
void
tearDownTheEnvironmentUsing(Closure $tearDown)
| internal |
Define the tearDown environment using callback.
in
InteractsWithPHPUnit at line 168
static void
setUpBeforeClassUsingPHPUnit()
| internal |
Cache uses for test case before class runs.
in
InteractsWithPHPUnit at line 178
static void
tearDownAfterClassUsingPHPUnit()
| internal |
Clear PHPUnit caches after class teardown.
in
InteractsWithPest at line 19
bool
isRunningTestCaseUsingPest()
Determine if the trait is used within testing using Pest.
in
InteractsWithPest at line 27
static protected bool
isRunningViaPestPrinter(object|string $object)
Determine if the object implements Pest test runner.
in
InteractsWithWorkbench at line 29
static string|null
applicationBasePathUsingWorkbench()
| internal |
Get Application's base path.
in
InteractsWithWorkbench at line 41
array|null
ignorePackageDiscoveriesFromUsingWorkbench()
| internal |
Ignore package discovery from.
in
InteractsWithWorkbench at line 59
protected array|null
getPackageBootstrappersUsingWorkbench(Application $app)
| internal |
Get package bootstrapper.
in
InteractsWithWorkbench at line 77
protected array|null
getPackageProvidersUsingWorkbench(Application $app)
| internal |
Get package providers.
in
InteractsWithWorkbench at line 104
protected string
applicationConsoleKernelUsingWorkbench(Application $app)
| internal |
Resolve application Console Kernel implementation.
in
InteractsWithWorkbench at line 118
protected string
applicationHttpKernelUsingWorkbench(Application $app)
| internal |
Get application HTTP Kernel implementation using Workbench.
in
InteractsWithWorkbench at line 132
protected string
applicationExceptionHandlerUsingWorkbench(Application $app)
| internal |
Get application HTTP exception handler using Workbench.
in
InteractsWithWorkbench at line 144
static Config|null
cachedConfigurationForWorkbench()
Get the cached Workbench configuration.
in
WithHypervelBootstrapFile at line 29
protected string|false
getApplicationBootstrapFile(string $filename)
| internal |
Get application bootstrap file path (if exists).
in
WithHypervelBootstrapFile at line 49
protected bool
hasCustomApplicationKernels()
| internal |
Determine if application is using a custom application kernels.
in
WithHypervelBootstrapFile at line 58
protected bool
usesTestbenchDefaultSkeleton()
Determine if application is bootstrapped using Testbench's default skeleton.
in
WithHypervelBootstrapFile at line 70
abstract protected string
getApplicationBasePath()
Get the application's base path.
in
CreatesApplication at line 83
static string
applicationBasePath()
Get the base path for the application.
in
CreatesApplication at line 95
array
ignorePackageDiscoveriesFrom()
Ignore package discovery from.
in
CreatesApplication at line 117
protected array
getPackageProviders(Application $app)
Get package providers.
in
CreatesApplication at line 129
protected array
getPackageBootstrappers(Application $app)
Get package bootstrappers.
in
CreatesApplication at line 144
protected array
getApplicationProviders(Application $app)
Get application providers.
Override in test classes to filter the default provider list before registration. For example, to remove SessionServiceProvider.
in
CreatesApplication at line 154
protected string|null
getApplicationTimezone(Application $app)
Get the application timezone.
in
CreatesApplication at line 169
protected array
overrideApplicationProviders(Application $app)
Override application providers.
Return a map of provider class names to replacements. Set a provider
to false to remove it entirely, or to another class name to replace it.
in
CreatesApplication at line 181
protected array
getApplicationAliases(Application $app)
Get application aliases.
in
CreatesApplication at line 193
protected array
overrideApplicationAliases(Application $app)
Override application aliases.
in
CreatesApplication at line 205
protected array
getPackageAliases(Application $app)
Get package aliases.
in
CreatesApplication at line 217
protected array
overrideApplicationBindings(Application $app)
Override application bindings.
in
CreatesApplication at line 230
protected void
defineEnvironment(Application $app)
Define environment setup.
Override in subclasses to modify config before providers boot. This is where test classes set database drivers, cache stores, etc.
in
CreatesApplication at line 245
Application
createApplication()
| internal |
Create the application instance.
Bootstraps the application manually step-by-step (like Orchestral Testbench's createApplication), rather than via kernel->bootstrap(), so defineEnvironment() can be called between RegisterProviders and BootProviders.
in
CreatesApplication at line 304
protected Application
resolveDefaultApplication()
| internal |
Create the default application implementation.
in
CreatesApplication at line 319
protected Application
resolveApplication()
Resolve the application instance.
in
CreatesApplication at line 339
protected void
resolveApplicationResolvingCallback(Application $app)
Resolve application resolving callback.
in
CreatesApplication at line 354
protected void
resolveApplicationFacades(Application $app)
Resolve application facades implementation.
in
CreatesApplication at line 365
protected void
resolveApplicationBindings(Application $app)
| internal |
Resolve application bindings.
in
CreatesApplication at line 377
protected void
resolveApplicationExceptionHandler(Application $app)
Resolve application HTTP exception handler.
in
CreatesApplication at line 387
protected void
resolveApplicationCore(Application $app)
| internal |
Resolve application core environment.
in
CreatesApplication at line 399
protected void
resolveApplicationEnvironmentVariables(Application $app)
| internal |
Resolve application environment variables.
in
CreatesApplication at line 441
protected void
resolveApplicationComposerVendorDirectory()
| internal |
Make a relative COMPOSER_VENDOR_DIR from the application environment absolute.
Child processes such as the skeleton's artisan resolve a relative value against their own base path rather than the package root. Bootstrapper already exported an inherited value; rewriting a loaded one through the repository keeps its putenv setting and restoration.
in
CreatesApplication at line 465
protected Closure
maskInheritedApplicationEnvironment()
Mask inherited framework APP_ENV for Testbench applications that opt out of loading env files.
The framework suite forces APP_ENV=testing globally via phpunit.xml.dist. Tests that disable environment loading should instead use the configuration defaults unless they explicitly provided APP_ENV or package-tester mode is enabled.
in
CreatesApplication at line 503
protected bool
hasConfiguredApplicationEnvironmentVariable(string $key)
Determine if the current test explicitly configured an environment variable.
in
CreatesApplication at line 517
protected void
resolveApplicationHttpKernel(Application $app)
Resolve application HTTP kernel implementation.
in
CreatesApplication at line 527
protected void
resolveApplicationHttpMiddlewares(Application $app)
| internal |
Resolve application HTTP default middlewares.
in
CreatesApplication at line 564
protected void
resolveApplicationConsoleKernel(Application $app)
Resolve application console kernel implementation.
in
CreatesApplication at line 580
protected void
resolveApplicationConfiguration(Application $app)
| internal |
Load configuration and register package providers/aliases.
Equivalent to Orchestral's resolveApplicationConfiguration(): loads config files, then sets app.providers and app.aliases in config BEFORE RegisterProviders reads them.
in
CreatesApplication at line 634
protected array
resolveApplicationAliases(Application $app)
| internal |
Resolve application aliases.
in
CreatesApplication at line 657
protected string|false
resolveApplicationRouteProvider(array $overrides)
Resolve the route provider from application provider overrides.
in
CreatesApplication at line 672
protected array
resolveApplicationProviders(Application $app)
| internal |
Resolve the final application provider list.
Merges package providers, then applies overrides (replacements/removals) to produce the list RegisterProviders uses.
in
CreatesApplication at line 704
protected void
resolveApplicationBootstrappers(Application $app)
| internal |
Run bootstrappers individually with defineEnvironment() inserted.
Equivalent to Orchestral's resolveApplicationBootstrappers().
in
CreatesApplication at line 764
protected void
refreshApplicationRouteNameLookups(Application $app)
| internal |
Refresh route name lookups now and whenever the URL generator is resolved.
Route names set via fluent ->name() after RouteCollection::add() are not indexed until refreshNameLookups() rebuilds the lookup table. This method ensures names are refreshed both immediately and lazily — the after_resolving callback catches routes defined inside test methods (after boot) by firing whenever app('url') is resolved.
in
CreatesApplication at line 781
protected void
resolveApplicationRateLimiting(Application $app)
Resolve application rate limiting configuration.
in
CreatesApplication at line 802
protected void
configureParallelCachePaths()
Configure worker-specific cache paths for parallel testing.
When running under ParaTest, each worker gets a unique route cache path to prevent filesystem races. Without this, one worker's defineCacheRoutes() writes a shared cache file that causes other workers' routesAreCached() to return true, skipping route setup.
in
CreatesApplication at line 820
protected string|null
paraTestWorkerToken()
Get the current ParaTest worker token before the application exists.
This reads the raw runtime arrays because cached route setup may run before parent::setUp(), when no application or ParallelTesting service has been created yet.
in
CreatesApplication at line 828
static protected Throwable|null
terminateAndFlushApplication(Application $app)
Terminate and flush an application, returning any cleanup failure.
in
HandlesAssertions at line 17
protected void
markTestSkippedUnless(bool|Closure $condition, string $message)
Mark the test as skipped when condition is not equivalent to true.
in
HandlesAssertions at line 27
protected void
markTestSkippedWhen(bool|Closure $condition, string $message)
Mark the test as skipped when condition is equivalent to true.
in
HandlesAttributes at line 31
protected FeaturesCollection
parseTestMethodAttributes(Application $app, string $attribute)
| internal |
Parse and execute test method attributes of a specific type.
Note: Attributes are already executed automatically via setUpTheTestEnvironmentUsingTestCase(). This method is for internal use by the testing infrastructure.
in
HandlesDatabases at line 30
protected void
setUpDatabaseRequirements(Closure $callback)
| internal |
Setup database requirements.
in
HandlesDatabases at line 76
protected bool
usesSqliteInMemoryDatabaseConnection(string|null $connection = null)
Determine if using in-memory SQLite database connection.
in
HandlesDatabases at line 96
protected void
defineDatabaseMigrations()
Define database migrations.
in
HandlesDatabases at line 106
protected void
defineDatabaseMigrationsAfterDatabaseRefreshed()
Define database migrations after database refreshed.
in
HandlesDatabases at line 116
protected void
destroyDatabaseMigrations()
Destroy database migrations.
in
HandlesDatabases at line 126
protected void
defineDatabaseSeeders()
Define database seeders.
in
HandlesRoutes at line 60
protected void
setUpApplicationRoutes(Application $app)
| internal |
Setup application routes.
in
HandlesRoutes at line 87
protected void
defineRoutes(Router $router)
Define routes setup.
in
HandlesRoutes at line 97
protected void
defineWebRoutes(Router $router)
Define web routes setup.
in
HandlesRoutes at line 107
protected void
defineStashRoutes(Closure|string $route)
Define stash routes setup.
in
HandlesRoutes at line 117
protected void
defineCacheRoutes(Closure|string $route, bool $cached = true)
Define cache routes setup.
in
HandlesRoutes at line 194
protected void
syncTestbenchRoutes()
| internal |
Synchronize Testbench routes.
in
HandlesRoutes at line 213
protected void
registerTestbenchRouteCleanup(Filesystem $files, string $cachedRoutesPath)
Register cleanup for route files and route cache written by this test.
in
HandlesRoutes at line 266
protected string
testbenchRouteFilePath(string $basePath)
Get a route file path owned by this test instance.
in
InteractsWithMigrations at line 39
protected void
setUpInteractsWithMigrations()
Setup the test environment.
in
InteractsWithMigrations at line 51
protected void
tearDownInteractsWithMigrations()
Teardown the test environment.
in
InteractsWithMigrations at line 95
protected void
loadMigrationsFrom(array|string $paths)
Define hooks to migrate the database before and after each test.
in
InteractsWithMigrations at line 116
protected bool
shouldRegisterMigrationPaths()
Determine whether migration paths should be registered for an upcoming migration.
in
InteractsWithMigrations at line 152
protected array
resolvePackageMigrationsOptions(array|string $paths = [])
| internal |
Resolve Package Migrations Artisan command options.
in
InteractsWithMigrations at line 172
protected void
loadHypervelMigrations(array|string $database = [])
Migrate Hypervel's default migrations.
in
InteractsWithMigrations at line 191
protected void
runHypervelMigrations(array|string $database = [])
Migrate all Hypervel migrations.
in
InteractsWithMigrations at line 207
protected array
resolveHypervelMigrationsOptions(array|string $database = [])
| internal |
Resolve Hypervel Migrations Artisan command options.
in
InteractsWithMigrations at line 217
protected void
runMigrationProcessor(Application $app, array $options)
Run and retain a migration processor for teardown.
in
InteractsWithMigrations at line 245
protected bool
usesInMemoryDatabaseForMigrationState()
Determine whether the active database concerns retain in-memory state.
in
InteractsWithMigrations at line 267
protected void
resetApplicationArtisanCommands(Application $app)
| internal |
Reset artisan commands for the application.
at line 32
protected void
reloadApplication()
Reload the application instance.