Application
class Application
Traits
Creates and bootstraps the application for testbench tests.
Provides per-worker database isolation for parallel testing.
Properties
| static protected string|null | $originalDatabaseName | The original database name before parallel suffixing. |
from InteractsWithParallelDatabase |
| static protected string|bool|null | $cacheApplicationBootstrapFile | Cached application bootstrap file path. |
from InteractsWithTestCase |
| static protected null|array<class-string, class-string> | $cachedTestCaseUses | Cached traits used by test case. |
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 |
| protected Application|null | $app | The Hypervel application instance. |
|
| protected array{env: array<int, string>, providers: array<int, class-string>, dont-discover: array<int, string>, bootstrappers: null|array<int, class-string>|class-string} | $config | List of configurations. |
|
| protected null|Application): void | $resolvingCallback | The application resolving callback. |
|
| protected bool | $loadEnvironmentVariables | Load environment variables from disk. |
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.
Check if the test case uses a specific trait.
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.
Execute BeforeAll lifecycle attributes.
Execute AfterAll lifecycle attributes and clear caches.
Determine if the container is running as a TestCase.
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.
Get package bootstrapper.
Get package providers.
Resolve application Console Kernel implementation.
Get application HTTP Kernel implementation using Workbench.
Get application HTTP exception handler using Workbench.
Define or get the cached uses for test case.
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.
Resolve the application's base path.
Ignore package discovery from.
Create the application instance.
Resolve application core environment variables implementation.
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.
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.
Create a new application resolver.
Create a new application resolver.
Create a new application resolver from configuration.
Create a new application instance.
Create a new application instance from configuration.
Create symlink to vendor path via new application instance.
Delete symlink to vendor path via new application instance.
Configure the application options.
Mask inherited framework APP_ENV for standalone Testbench apps.
Determine if an environment variable was provided via Testbench config.
Flush static state touched by Testbench application bootstrap tests.
Details
in
InteractsWithParallelDatabase at line 45
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 86
protected void
ensureParallelDatabaseExists()
Ensure the per-worker database exists, creating it if needed.
Called from database testing traits (RefreshDatabase, DatabaseMigrations, 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 132
protected bool
shouldManageParallelDatabase(mixed $driver, string $database)
Determine if the database should be managed for parallel testing.
in
InteractsWithParallelDatabase at line 159
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)
Check if the test case uses a specific trait.
in
InteractsWithTestCase at line 62
static bool
usesRefreshDatabaseTestingConcern()
Determine if the test case uses refresh-database testing concerns.
in
InteractsWithTestCase at line 73
static array
cachedUsesForTestCase()
Cache and return traits used by test case.
in
InteractsWithTestCase at line 87
static void
usesTestingFeature(object $attribute, int $flag = Attribute::TARGET_CLASS)
Programmatically add a testing feature attribute.
in
InteractsWithTestCase at line 118
abstract static protected Collection
resolvePhpUnitAttributesForMethod(string $className, string|null $methodName = null)
Resolve PHPUnit method attributes for specific method.
in
InteractsWithTestCase at line 123
protected void
setUpTheTestEnvironmentUsingTestCase()
Execute BeforeEach lifecycle attributes.
in
InteractsWithTestCase at line 136
protected void
tearDownTheTestEnvironmentUsingTestCase()
Execute AfterEach lifecycle attributes.
in
InteractsWithTestCase at line 167
static void
setUpBeforeClassUsingTestCase()
Execute BeforeAll lifecycle attributes.
in
InteractsWithTestCase at line 178
static void
tearDownAfterClassUsingTestCase()
Execute AfterAll lifecycle attributes and clear caches.
at line 198
bool
isRunningTestCase()
Determine if the container is running as a TestCase.
in
InteractsWithPHPUnit at line 64
string|null
resolvePhpUnitTestClassName()
Resolve the PHPUnit test class name.
in
InteractsWithPHPUnit at line 78
string|null
resolvePhpUnitTestMethodName()
Resolve the PHPUnit test method name.
in
InteractsWithPHPUnit at line 92
protected Collection
resolvePhpUnitAttributes()
Resolve and cache PHPUnit attributes for current test.
in
InteractsWithPHPUnit at line 142
void
setUpTheEnvironmentUsing(Closure $setUp)
Define the setUp environment using callback.
in
InteractsWithPHPUnit at line 152
void
tearDownTheEnvironmentUsing(Closure $tearDown)
Define the tearDown environment using callback.
in
InteractsWithPHPUnit at line 160
static void
setUpBeforeClassUsingPHPUnit()
Cache uses for test case before class runs.
in
InteractsWithPHPUnit at line 168
static void
tearDownAfterClassUsingPHPUnit()
Clear PHPUnit caches after class teardown.
in
InteractsWithPest at line 17
bool
isRunningTestCaseUsingPest()
Determine if the trait is used within testing using Pest.
in
InteractsWithPest at line 25
static protected bool
isRunningViaPestPrinter(object|string $object)
Determine if the object implements Pest test runner.
in
InteractsWithWorkbench at line 25
static string|null
applicationBasePathUsingWorkbench()
| internal |
Get Application's base path.
in
InteractsWithWorkbench at line 37
array|null
ignorePackageDiscoveriesFromUsingWorkbench()
| internal |
Ignore package discovery from.
in
InteractsWithWorkbench at line 55
protected array|null
getPackageBootstrappersUsingWorkbench(object $app)
| internal |
Get package bootstrapper.
in
InteractsWithWorkbench at line 73
protected array|null
getPackageProvidersUsingWorkbench(object $app)
| internal |
Get package providers.
in
InteractsWithWorkbench at line 100
protected string
applicationConsoleKernelUsingWorkbench(object $app)
| internal |
Resolve application Console Kernel implementation.
in
InteractsWithWorkbench at line 114
protected string
applicationHttpKernelUsingWorkbench(object $app)
| internal |
Get application HTTP Kernel implementation using Workbench.
in
InteractsWithWorkbench at line 128
protected string
applicationExceptionHandlerUsingWorkbench(object $app)
| internal |
Get application HTTP exception handler using Workbench.
in
InteractsWithWorkbench at line 140
static Config|null
cachedConfigurationForWorkbench()
Define or get the cached uses for test case.
in
WithHypervelBootstrapFile at line 20
protected string|false
getApplicationBootstrapFile(string $filename)
| internal |
Get application bootstrap file path (if exists).
in
WithHypervelBootstrapFile at line 40
protected bool
hasCustomApplicationKernels()
| internal |
Determine if application is using a custom application kernels.
in
WithHypervelBootstrapFile at line 49
protected bool
usesTestbenchDefaultSkeleton()
Determine if application is bootstrapped using Testbench's default skeleton.
at line 334
protected string
getApplicationBasePath()
Resolve the application's base path.
in
CreatesApplication at line 64
static string
applicationBasePath()
Get the base path for the application.
at line 208
array
ignorePackageDiscoveriesFrom()
Ignore package discovery from.
at line 310
protected array
getPackageProviders(Application $app)
Get the package providers.
at line 320
protected array
getPackageBootstrappers(Application $app)
Get the package bootstrappers.
in
CreatesApplication at line 115
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 123
protected string|null
getApplicationTimezone(Application $app)
Get the application timezone.
in
CreatesApplication at line 136
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 146
protected array
getPackageAliases(Application $app)
Get package aliases.
in
CreatesApplication at line 156
protected array
overrideApplicationBindings(Application $app)
Override application bindings.
in
CreatesApplication at line 167
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.
at line 216
Application
createApplication()
Create the application instance.
in
CreatesApplication at line 209
protected Application
resolveApplication()
Resolve the application instance.
in
CreatesApplication at line 230
protected void
resolveApplicationBindings(Application $app)
Resolve application bindings.
in
CreatesApplication at line 240
protected void
resolveApplicationExceptionHandler(Application $app)
Resolve application HTTP exception handler.
in
CreatesApplication at line 248
protected void
resolveApplicationCore(Application $app)
Resolve application core environment.
at line 342
protected void
resolveApplicationEnvironmentVariables(Application $app)
Resolve application core environment variables implementation.
in
CreatesApplication at line 299
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 340
protected bool
hasConfiguredApplicationEnvironmentVariable(string $key)
Determine if the current test explicitly configured an environment variable.
in
CreatesApplication at line 352
protected void
resolveApplicationHttpKernel(Application $app)
Resolve application HTTP kernel implementation.
in
CreatesApplication at line 360
protected void
resolveApplicationHttpMiddlewares(Application $app)
Resolve application HTTP default middlewares.
in
CreatesApplication at line 391
protected void
resolveApplicationConsoleKernel(Application $app)
Resolve application console kernel implementation.
at line 360
protected void
resolveApplicationConfiguration(Application $app)
Load configuration and register package providers/aliases.
in
CreatesApplication at line 453
protected void
resolveApplicationProviders(Application $app)
Resolve the final application provider list.
Merges package providers, then applies overrides (replacements/removals) before writing the final list to config for RegisterProviders to use.
in
CreatesApplication at line 482
protected void
resolveApplicationBootstrappers(Application $app)
Run bootstrappers individually with defineEnvironment() inserted.
Equivalent to Orchestral's resolveApplicationBootstrappers().
in
CreatesApplication at line 538
protected void
refreshApplicationRouteNameLookups(Application $app)
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 553
protected void
registerPackageAliases(Application $app)
Register package aliases into config.
in
CreatesApplication at line 574
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 592
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.
at line 89
__construct(string|null $basePath = null, callable|null $resolvingCallback = null)
Create a new application resolver.
at line 102
static Application
make(string|null $basePath = null, callable|null $resolvingCallback = null, array $options = [])
Create a new application resolver.
at line 113
static Application
makeFromConfig(Config $config, callable|null $resolvingCallback = null, array $options = [])
Create a new application resolver from configuration.
at line 129
static Application
create(string|null $basePath = null, callable|null $resolvingCallback = null, array $options = [])
Create a new application instance.
at line 140
static Application
createFromConfig(Config $config, callable|null $resolvingCallback = null, array $options = [])
Create a new application instance from configuration.
at line 148
static Application
createVendorSymlink(string|null $basePath, string $workingVendorPath)
Create symlink to vendor path via new application instance.
at line 160
static Application
deleteVendorSymlink(string|null $basePath)
Delete symlink to vendor path via new application instance.
at line 175
Application
configure(array $options)
Configure the application options.
at line 245
protected Closure
maskInheritedStandaloneEnvironment()
Mask inherited framework APP_ENV for standalone Testbench apps.
The framework suite forces APP_ENV=testing globally via phpunit.xml.dist. Standalone Testbench applications should instead use the workbench config default unless the caller explicitly supplied APP_ENV or requested on-disk environment loading.
at line 290
protected bool
hasConfiguredEnvironmentVariable(string $key)
Determine if an environment variable was provided via Testbench config.
at line 375
static void
flushState(object $instance)
Flush static state touched by Testbench application bootstrap tests.
IMPORTANT: This is NOT the global framework static-state cleanup list. Do not add general framework static-state resets here. Add them to src/testing/src/PHPUnit/AfterEachTestSubscriber.php instead.