trait CreatesApplication

Creates and bootstraps the application for testbench tests.

Mirrors Orchestral Testbench's CreatesApplication: bootstrappers are called individually so defineEnvironment() can modify config between RegisterProviders and BootProviders. The testbench Console Kernel returns an empty bootstrapper list, so the final bootstrap() call only sets hasBeenBootstrapped and loads commands.

Traits

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
null|bool $loadEnvironmentVariables

Methods

void
configureParallelDatabaseName(mixed $app)

Rewrite the default connection's database name for parallel testing.

void
ensureParallelDatabaseExists()

Ensure the per-worker database exists, creating it if needed.

bool
shouldManageParallelDatabase(mixed $driver, string $database)

Determine if the database should be managed for parallel testing.

string
parallelTestDatabase(string $database, string $token)

Get the per-worker test database name.

static bool
usesTestingConcern(string|null $trait = null)

Determine if the test case uses the given trait, or the Testing trait by default.

static bool
usesRefreshDatabaseTestingConcern()

Determine if the test case uses refresh-database testing concerns.

static array
cachedUsesForTestCase()

Cache and return traits used by test case.

static void
usesTestingFeature(object $attribute, int $flag = Attribute::TARGET_CLASS)

Programmatically add a testing feature attribute.

static Collection
resolvePhpUnitAttributesForMethod(string $className, string|null $methodName = null)

Resolve PHPUnit method attributes for specific method.

void
setUpTheTestEnvironmentUsingTestCase()

Execute BeforeEach lifecycle attributes.

void
tearDownTheTestEnvironmentUsingTestCase()

Execute AfterEach lifecycle attributes.

static void
setUpBeforeClassUsingTestCase()

Load test fixtures and execute BeforeAll lifecycle attributes.

static void
tearDownAfterClassUsingTestCase()

Execute AfterAll lifecycle attributes and clear caches.

bool
isRunningTestCase()

Determine if the object is running as a PHPUnit test case.

string|null
resolvePhpUnitTestClassName()

Resolve the PHPUnit test class name.

string|null
resolvePhpUnitTestMethodName()

Resolve the PHPUnit test method name.

resolvePhpUnitAttributes()

Resolve and cache PHPUnit attributes for current test.

void
setUpTheEnvironmentUsing(Closure $setUp)

Define the setUp environment using callback.

void
tearDownTheEnvironmentUsing(Closure $tearDown)

Define the tearDown environment using callback.

static void
setUpBeforeClassUsingPHPUnit()

Cache uses for test case before class runs.

static void
tearDownAfterClassUsingPHPUnit()

Clear PHPUnit caches after class teardown.

bool
isRunningTestCaseUsingPest()

Determine if the trait is used within testing using Pest.

static bool
isRunningViaPestPrinter(object|string $object)

Determine if the object implements Pest test runner.

static string|null
applicationBasePathUsingWorkbench()

Get Application's base path.

array|null
ignorePackageDiscoveriesFromUsingWorkbench()

Ignore package discovery from.

array|null
getPackageBootstrappersUsingWorkbench(Application $app)

Get package bootstrapper.

array|null
getPackageProvidersUsingWorkbench(Application $app)

Get package providers.

string
applicationConsoleKernelUsingWorkbench(Application $app)

Resolve application Console Kernel implementation.

string
applicationHttpKernelUsingWorkbench(Application $app)

Get application HTTP Kernel implementation using Workbench.

string
applicationExceptionHandlerUsingWorkbench(Application $app)

Get application HTTP exception handler using Workbench.

static Config|null
cachedConfigurationForWorkbench()

Get the cached Workbench configuration.

string|false
getApplicationBootstrapFile(string $filename)

Get application bootstrap file path (if exists).

bool
hasCustomApplicationKernels()

Determine if application is using a custom application kernels.

bool
usesTestbenchDefaultSkeleton()

Determine if application is bootstrapped using Testbench's default skeleton.

string
getApplicationBasePath()

Resolve the application's base path.

static string
applicationBasePath()

Get the base path for the application.

array
ignorePackageDiscoveriesFrom()

Ignore package discovery from.

array
getPackageProviders(Application $app)

Get package providers.

array
getPackageBootstrappers(Application $app)

Get package bootstrappers.

array
getApplicationProviders(Application $app)

Get application providers.

string|null
getApplicationTimezone(Application $app)

Get the application timezone.

array
overrideApplicationProviders(Application $app)

Override application providers.

array
getApplicationAliases(Application $app)

Get application aliases.

array
overrideApplicationAliases(Application $app)

Override application aliases.

array
getPackageAliases(Application $app)

Get package aliases.

array
overrideApplicationBindings(Application $app)

Override application bindings.

void
defineEnvironment(Application $app)

Define environment setup.

createApplication()

Create the application instance.

resolveDefaultApplication()

Create the default application implementation.

resolveApplication()

Resolve the application instance.

void
resolveApplicationResolvingCallback(Application $app)

Resolve application resolving callback.

void
resolveApplicationFacades(Application $app)

Resolve application facades implementation.

void
resolveApplicationBindings(Application $app)

Resolve application bindings.

void
resolveApplicationExceptionHandler(Application $app)

Resolve application HTTP exception handler.

void
resolveApplicationCore(Application $app)

Resolve application core environment.

void
resolveApplicationEnvironmentVariables(Application $app)

Resolve application environment variables.

void
resolveApplicationComposerVendorDirectory()

Make a relative COMPOSER_VENDOR_DIR from the application environment absolute.

maskInheritedApplicationEnvironment()

Mask inherited framework APP_ENV for Testbench applications that opt out of loading env files.

bool
hasConfiguredApplicationEnvironmentVariable(string $key)

Determine if the current test explicitly configured an environment variable.

void
resolveApplicationHttpKernel(Application $app)

Resolve application HTTP kernel implementation.

void
resolveApplicationHttpMiddlewares(Application $app)

Resolve application HTTP default middlewares.

void
resolveApplicationConsoleKernel(Application $app)

Resolve application console kernel implementation.

void
resolveApplicationConfiguration(Application $app)

Load configuration and register package providers/aliases.

array
resolveApplicationAliases(Application $app)

Resolve application aliases.

string|false
resolveApplicationRouteProvider(array $overrides)

Resolve the route provider from application provider overrides.

array
resolveApplicationProviders(Application $app)

Resolve the final application provider list.

void
resolveApplicationBootstrappers(Application $app)

Run bootstrappers individually with defineEnvironment() inserted.

void
refreshApplicationRouteNameLookups(Application $app)

Refresh route name lookups now and whenever the URL generator is resolved.

void
resolveApplicationRateLimiting(Application $app)

Resolve application rate limiting configuration.

void
configureParallelCachePaths()

Configure worker-specific cache paths for parallel testing.

string|null
paraTestWorkerToken()

Get the current ParaTest worker token before the application exists.

static Throwable|null
terminateAndFlushApplication(Application $app)

Terminate and flush an application, returning any cleanup failure.

Details

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.

Parameters

mixed $app

Return Value

void

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.

Return Value

void

protected bool shouldManageParallelDatabase(mixed $driver, string $database)

Determine if the database should be managed for parallel testing.

Parameters

mixed $driver
string $database

Return Value

bool

protected string parallelTestDatabase(string $database, string $token)

Get the per-worker test database name.

Parameters

string $database
string $token

Return Value

string

static bool usesTestingConcern(string|null $trait = null)

Determine if the test case uses the given trait, or the Testing trait by default.

Parameters

string|null $trait

Return Value

bool

static bool usesRefreshDatabaseTestingConcern()

Determine if the test case uses refresh-database testing concerns.

Return Value

bool

static array cachedUsesForTestCase()

internal  
 

Cache and return traits used by test case.

Return Value

array

static void usesTestingFeature(object $attribute, int $flag = Attribute::TARGET_CLASS)

Programmatically add a testing feature attribute.

Parameters

object $attribute
int $flag

Return Value

void

abstract static protected Collection resolvePhpUnitAttributesForMethod(string $className, string|null $methodName = null)

Resolve PHPUnit method attributes for specific method.

Parameters

string $className
string|null $methodName

Return Value

Collection

protected void setUpTheTestEnvironmentUsingTestCase()

internal  
 

Execute BeforeEach lifecycle attributes.

Return Value

void

protected void tearDownTheTestEnvironmentUsingTestCase()

internal  
 

Execute AfterEach lifecycle attributes.

Return Value

void

static void setUpBeforeClassUsingTestCase()

internal  
 

Load test fixtures and execute BeforeAll lifecycle attributes.

Return Value

void

static void tearDownAfterClassUsingTestCase()

internal  
 

Execute AfterAll lifecycle attributes and clear caches.

Return Value

void

bool isRunningTestCase()

Determine if the object is running as a PHPUnit test case.

Return Value

bool

string|null resolvePhpUnitTestClassName()

internal  
 

Resolve the PHPUnit test class name.

Return Value

string|null

string|null resolvePhpUnitTestMethodName()

internal  
 

Resolve the PHPUnit test method name.

Return Value

string|null

in InteractsWithPHPUnit at line 100
protected Collection resolvePhpUnitAttributes()

internal  
 

Resolve and cache PHPUnit attributes for current test.

Return Value

Collection

in InteractsWithPHPUnit at line 146
void setUpTheEnvironmentUsing(Closure $setUp)

internal  
 

Define the setUp environment using callback.

Parameters

Closure $setUp

Return Value

void

in InteractsWithPHPUnit at line 158
void tearDownTheEnvironmentUsing(Closure $tearDown)

internal  
 

Define the tearDown environment using callback.

Parameters

Closure $tearDown

Return Value

void

in InteractsWithPHPUnit at line 168
static void setUpBeforeClassUsingPHPUnit()

internal  
 

Cache uses for test case before class runs.

Return Value

void

in InteractsWithPHPUnit at line 178
static void tearDownAfterClassUsingPHPUnit()

internal  
 

Clear PHPUnit caches after class teardown.

Return Value

void

in InteractsWithPest at line 19
bool isRunningTestCaseUsingPest()

Determine if the trait is used within testing using Pest.

Return Value

bool

in InteractsWithPest at line 27
static protected bool isRunningViaPestPrinter(object|string $object)

Determine if the object implements Pest test runner.

Parameters

object|string $object

Return Value

bool

static string|null applicationBasePathUsingWorkbench()

internal  
 

Get Application's base path.

Return Value

string|null

array|null ignorePackageDiscoveriesFromUsingWorkbench()

internal  
 

Ignore package discovery from.

Return Value

array|null

protected array|null getPackageBootstrappersUsingWorkbench(Application $app)

internal  
 

Get package bootstrapper.

Parameters

Application $app

Return Value

array|null

protected array|null getPackageProvidersUsingWorkbench(Application $app)

internal  
 

Get package providers.

Parameters

Application $app

Return Value

array|null

protected string applicationConsoleKernelUsingWorkbench(Application $app)

internal  
 

Resolve application Console Kernel implementation.

Parameters

Application $app

Return Value

string

protected string applicationHttpKernelUsingWorkbench(Application $app)

internal  
 

Get application HTTP Kernel implementation using Workbench.

Parameters

Application $app

Return Value

string

protected string applicationExceptionHandlerUsingWorkbench(Application $app)

internal  
 

Get application HTTP exception handler using Workbench.

Parameters

Application $app

Return Value

string

static Config|null cachedConfigurationForWorkbench()

Get the cached Workbench configuration.

Return Value

Config|null

protected string|false getApplicationBootstrapFile(string $filename)

internal  
 

Get application bootstrap file path (if exists).

Parameters

string $filename

Return Value

string|false

protected bool hasCustomApplicationKernels()

internal  
 

Determine if application is using a custom application kernels.

Return Value

bool

protected bool usesTestbenchDefaultSkeleton()

Determine if application is bootstrapped using Testbench's default skeleton.

Return Value

bool

at line 105
protected string getApplicationBasePath()

internal  
 

Resolve the application's base path.

Return Value

string

at line 83
static string applicationBasePath()

Get the base path for the application.

Return Value

string

at line 95
array ignorePackageDiscoveriesFrom()

Ignore package discovery from.

Return Value

array

at line 117
protected array getPackageProviders(Application $app)

Get package providers.

Parameters

Application $app

Return Value

array

at line 129
protected array getPackageBootstrappers(Application $app)

Get package bootstrappers.

Parameters

Application $app

Return Value

array

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.

Parameters

Application $app

Return Value

array

at line 154
protected string|null getApplicationTimezone(Application $app)

Get the application timezone.

Parameters

Application $app

Return Value

string|null

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.

Parameters

Application $app

Return Value

array

at line 181
protected array getApplicationAliases(Application $app)

Get application aliases.

Parameters

Application $app

Return Value

array

at line 193
protected array overrideApplicationAliases(Application $app)

Override application aliases.

Parameters

Application $app

Return Value

array

at line 205
protected array getPackageAliases(Application $app)

Get package aliases.

Parameters

Application $app

Return Value

array

at line 217
protected array overrideApplicationBindings(Application $app)

Override application bindings.

Parameters

Application $app

Return Value

array

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.

Parameters

Application $app

Return Value

void

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.

Return Value

Application

at line 304
protected Application resolveDefaultApplication()

internal  
 

Create the default application implementation.

Return Value

Application

at line 319
protected Application resolveApplication()

Resolve the application instance.

Return Value

Application

at line 339
protected void resolveApplicationResolvingCallback(Application $app)

Resolve application resolving callback.

Parameters

Application $app

Return Value

void

at line 354
protected void resolveApplicationFacades(Application $app)

Resolve application facades implementation.

Parameters

Application $app

Return Value

void

at line 365
protected void resolveApplicationBindings(Application $app)

internal  
 

Resolve application bindings.

Parameters

Application $app

Return Value

void

at line 377
protected void resolveApplicationExceptionHandler(Application $app)

Resolve application HTTP exception handler.

Parameters

Application $app

Return Value

void

at line 387
protected void resolveApplicationCore(Application $app)

internal  
 

Resolve application core environment.

Parameters

Application $app

Return Value

void

at line 399
protected void resolveApplicationEnvironmentVariables(Application $app)

internal  
 

Resolve application environment variables.

Parameters

Application $app

Return Value

void

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.

Return Value

void

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.

Return Value

Closure

at line 503
protected bool hasConfiguredApplicationEnvironmentVariable(string $key)

Determine if the current test explicitly configured an environment variable.

Parameters

string $key

Return Value

bool

at line 517
protected void resolveApplicationHttpKernel(Application $app)

Resolve application HTTP kernel implementation.

Parameters

Application $app

Return Value

void

at line 527
protected void resolveApplicationHttpMiddlewares(Application $app)

internal  
 

Resolve application HTTP default middlewares.

Parameters

Application $app

Return Value

void

at line 564
protected void resolveApplicationConsoleKernel(Application $app)

Resolve application console kernel implementation.

Parameters

Application $app

Return Value

void

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.

Parameters

Application $app

Return Value

void

at line 634
protected array resolveApplicationAliases(Application $app)

internal  
 

Resolve application aliases.

Parameters

Application $app

Return Value

array

at line 657
protected string|false resolveApplicationRouteProvider(array $overrides)

Resolve the route provider from application provider overrides.

Parameters

array $overrides

Return Value

string|false

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.

Parameters

Application $app

Return Value

array

at line 704
protected void resolveApplicationBootstrappers(Application $app)

internal  
 

Run bootstrappers individually with defineEnvironment() inserted.

Equivalent to Orchestral's resolveApplicationBootstrappers().

Parameters

Application $app

Return Value

void

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.

Parameters

Application $app

Return Value

void

at line 781
protected void resolveApplicationRateLimiting(Application $app)

Resolve application rate limiting configuration.

Parameters

Application $app

Return Value

void

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.

Return Value

void

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.

Return Value

string|null

at line 828
static protected Throwable|null terminateAndFlushApplication(Application $app)

Terminate and flush an application, returning any cleanup failure.

Parameters

Application $app

Return Value

Throwable|null