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

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
null|Application $app from  InteractsWithPHPUnit
protected bool $requireApplicationCachedRoutesHasRun

Whether cached routes have been loaded 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 from  InteractsWithMigrations

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)

Check if the test case uses a specific trait.

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()

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(object $app)

Get package bootstrapper.

array|null
getPackageProvidersUsingWorkbench(object $app)

Get package providers.

string
applicationConsoleKernelUsingWorkbench(object $app)

Resolve application Console Kernel implementation.

string
applicationHttpKernelUsingWorkbench(object $app)

Get application HTTP Kernel implementation using Workbench.

string
applicationExceptionHandlerUsingWorkbench(object $app)

Get application HTTP exception handler using Workbench.

static Config|null
cachedConfigurationForWorkbench()

Define or get the cached uses for test case.

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()

Get 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
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.

resolveApplication()

Resolve the application instance.

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.

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.

void
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
registerPackageAliases(Application $app)

Register package aliases into config.

void
configureParallelCachePaths()

Configure worker-specific cache paths for parallel testing.

string|null
paraTestWorkerToken()

Get the current ParaTest worker token before the application exists.

void
markTestSkippedUnless(bool|Closure|null $condition, string $message)

Mark the test as skipped when condition is not equivalent to true.

void
markTestSkippedWhen(bool|Closure|null $condition, string $message)

Mark the test as skipped when condition is equivalent to true.

parseTestMethodAttributes(Application $app, string $attribute)

Parse and execute test method attributes of a specific type.

void
setUpDatabaseRequirements(Closure $callback)

Setup database requirements.

bool
usesSqliteInMemoryDatabaseConnection(string|null $connection = null)

Determine if using in-memory SQLite database connection.

void
defineDatabaseMigrations()

Define database migrations.

void
defineDatabaseMigrationsAfterDatabaseRefreshed()

Define database migrations after database refreshed.

void
destroyDatabaseMigrations()

Destroy database migrations.

void
defineDatabaseSeeders()

Define database seeders.

void
setUpApplicationRoutes(Application $app)

Setup application routes.

void
defineRoutes(Router $router)

Define routes setup.

void
defineWebRoutes(Router $router)

Define web routes setup.

void
defineStashRoutes(Closure|string $route)

Define stash routes setup.

void
defineCacheRoutes(Closure|string $route, bool $cached = true)

Define cache routes setup.

void
requireApplicationCachedRoutes(Filesystem $files, bool $cached)

Require application cached routes.

void
registerTestbenchRouteCleanup(Filesystem $files)

Register cleanup for route files and route cache written by this test.

string
testbenchRouteFilePath(string $basePath)

Get a route file path owned by this test instance.

void
loadMigrationsFrom(array|string $paths)

No description

array
resolvePackageMigrationsOptions(array|string $paths = [])

No description

void
loadHypervelMigrations(array|string $database = [])

Migrate Hypervel's default migrations.

void
runHypervelMigrations(array|string $database = [])

Migrate all Hypervel migrations.

array
resolveHypervelMigrationsOptions(array|string $database = [])

No description

void
reloadApplication()

Reload the application instance.

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 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.

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)

Check if the test case uses a specific trait.

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()

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()

Execute BeforeEach lifecycle attributes.

Return Value

void

protected void tearDownTheTestEnvironmentUsingTestCase()

Execute AfterEach lifecycle attributes.

Return Value

void

static void setUpBeforeClassUsingTestCase()

Execute BeforeAll lifecycle attributes.

Return Value

void

static void tearDownAfterClassUsingTestCase()

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()

Resolve the PHPUnit test class name.

Return Value

string|null

string|null resolvePhpUnitTestMethodName()

Resolve the PHPUnit test method name.

Return Value

string|null

protected Collection resolvePhpUnitAttributes()

Resolve and cache PHPUnit attributes for current test.

Return Value

Collection

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

Define the setUp environment using callback.

Parameters

Closure $setUp

Return Value

void

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

Define the tearDown environment using callback.

Parameters

Closure $tearDown

Return Value

void

in InteractsWithPHPUnit at line 160
static void setUpBeforeClassUsingPHPUnit()

Cache uses for test case before class runs.

Return Value

void

in InteractsWithPHPUnit at line 168
static void tearDownAfterClassUsingPHPUnit()

Clear PHPUnit caches after class teardown.

Return Value

void

in InteractsWithPest at line 17
bool isRunningTestCaseUsingPest()

Determine if the trait is used within testing using Pest.

Return Value

bool

in InteractsWithPest at line 25
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(object $app)

internal  
 

Get package bootstrapper.

Parameters

object $app

Return Value

array|null

protected array|null getPackageProvidersUsingWorkbench(object $app)

internal  
 

Get package providers.

Parameters

object $app

Return Value

array|null

protected string applicationConsoleKernelUsingWorkbench(object $app)

internal  
 

Resolve application Console Kernel implementation.

Parameters

object $app

Return Value

string

protected string applicationHttpKernelUsingWorkbench(object $app)

internal  
 

Get application HTTP Kernel implementation using Workbench.

Parameters

object $app

Return Value

string

protected string applicationExceptionHandlerUsingWorkbench(object $app)

internal  
 

Get application HTTP exception handler using Workbench.

Parameters

object $app

Return Value

string

static Config|null cachedConfigurationForWorkbench()

Define or get the cached uses for test case.

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

abstract protected string getApplicationBasePath()

Get the application's base path.

Return Value

string

in CreatesApplication at line 64
static string applicationBasePath()

Get the base path for the application.

Return Value

string

in CreatesApplication at line 74
array ignorePackageDiscoveriesFrom()

Ignore package discovery from.

Return Value

array

in CreatesApplication at line 92
protected array getPackageProviders(Application $app)

Get package providers.

Parameters

Application $app

Return Value

array

in CreatesApplication at line 102
protected array getPackageBootstrappers(Application $app)

Get package bootstrappers.

Parameters

Application $app

Return Value

array

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.

Parameters

Application $app

Return Value

array

in CreatesApplication at line 123
protected string|null getApplicationTimezone(Application $app)

Get the application timezone.

Parameters

Application $app

Return Value

string|null

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.

Parameters

Application $app

Return Value

array

in CreatesApplication at line 146
protected array getPackageAliases(Application $app)

Get package aliases.

Parameters

Application $app

Return Value

array

in CreatesApplication at line 156
protected array overrideApplicationBindings(Application $app)

Override application bindings.

Parameters

Application $app

Return Value

array

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.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 180
Application createApplication()

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

in CreatesApplication at line 209
protected Application resolveApplication()

Resolve the application instance.

Return Value

Application

in CreatesApplication at line 230
protected void resolveApplicationBindings(Application $app)

Resolve application bindings.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 240
protected void resolveApplicationExceptionHandler(Application $app)

Resolve application HTTP exception handler.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 248
protected void resolveApplicationCore(Application $app)

Resolve application core environment.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 258
protected void resolveApplicationEnvironmentVariables(Application $app)

Resolve application environment variables.

Parameters

Application $app

Return Value

void

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.

Return Value

Closure

in CreatesApplication at line 340
protected bool hasConfiguredApplicationEnvironmentVariable(string $key)

Determine if the current test explicitly configured an environment variable.

Parameters

string $key

Return Value

bool

in CreatesApplication at line 352
protected void resolveApplicationHttpKernel(Application $app)

Resolve application HTTP kernel implementation.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 360
protected void resolveApplicationHttpMiddlewares(Application $app)

Resolve application HTTP default middlewares.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 391
protected void resolveApplicationConsoleKernel(Application $app)

Resolve application console kernel implementation.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 405
protected void resolveApplicationConfiguration(Application $app)

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

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.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 482
protected void resolveApplicationBootstrappers(Application $app)

Run bootstrappers individually with defineEnvironment() inserted.

Equivalent to Orchestral's resolveApplicationBootstrappers().

Parameters

Application $app

Return Value

void

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.

Parameters

Application $app

Return Value

void

in CreatesApplication at line 553
protected void registerPackageAliases(Application $app)

Register package aliases into config.

Parameters

Application $app

Return Value

void

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.

Return Value

void

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.

Return Value

string|null

in HandlesAssertions at line 19
protected void markTestSkippedUnless(bool|Closure|null $condition, string $message)

Mark the test as skipped when condition is not equivalent to true.

Parameters

bool|Closure|null $condition
string $message

Return Value

void

in HandlesAssertions at line 32
protected void markTestSkippedWhen(bool|Closure|null $condition, string $message)

Mark the test as skipped when condition is equivalent to true.

Parameters

bool|Closure|null $condition
string $message

Return Value

void

in HandlesAttributes at line 28
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.

Parameters

Application $app
string $attribute

Return Value

FeaturesCollection

in HandlesDatabases at line 27
protected void setUpDatabaseRequirements(Closure $callback)

Setup database requirements.

Parameters

Closure $callback

Return Value

void

in HandlesDatabases at line 76
protected bool usesSqliteInMemoryDatabaseConnection(string|null $connection = null)

Determine if using in-memory SQLite database connection.

Parameters

string|null $connection

Return Value

bool

in HandlesDatabases at line 98
protected void defineDatabaseMigrations()

Define database migrations.

Return Value

void

in HandlesDatabases at line 106
protected void defineDatabaseMigrationsAfterDatabaseRefreshed()

Define database migrations after database refreshed.

Return Value

void

in HandlesDatabases at line 114
protected void destroyDatabaseMigrations()

Destroy database migrations.

Return Value

void

in HandlesDatabases at line 122
protected void defineDatabaseSeeders()

Define database seeders.

Return Value

void

in HandlesRoutes at line 56
protected void setUpApplicationRoutes(Application $app)

Setup application routes.

Parameters

Application $app

Return Value

void

in HandlesRoutes at line 88
protected void defineRoutes(Router $router)

Define routes setup.

Parameters

Router $router

Return Value

void

in HandlesRoutes at line 96
protected void defineWebRoutes(Router $router)

Define web routes setup.

Parameters

Router $router

Return Value

void

in HandlesRoutes at line 104
protected void defineStashRoutes(Closure|string $route)

Define stash routes setup.

Parameters

Closure|string $route

Return Value

void

in HandlesRoutes at line 112
protected void defineCacheRoutes(Closure|string $route, bool $cached = true)

Define cache routes setup.

Parameters

Closure|string $route
bool $cached

Return Value

void

in HandlesRoutes at line 184
protected void requireApplicationCachedRoutes(Filesystem $files, bool $cached)

internal  
 

Require application cached routes.

Parameters

Filesystem $files
bool $cached

Return Value

void

in HandlesRoutes at line 208
protected void registerTestbenchRouteCleanup(Filesystem $files)

Register cleanup for route files and route cache written by this test.

Parameters

Filesystem $files

Return Value

void

in HandlesRoutes at line 234
protected string testbenchRouteFilePath(string $basePath)

Get a route file path owned by this test instance.

Parameters

string $basePath

Return Value

string

protected void setUpInteractsWithMigrations()

No description

Return Value

void

protected void tearDownInteractsWithMigrations()

No description

Return Value

void

protected void loadMigrationsFrom(array|string $paths)

No description

Parameters

array|string $paths

Return Value

void

protected array resolvePackageMigrationsOptions(array|string $paths = [])

internal  
 

No description

Parameters

array|string $paths

Return Value

array

protected void loadHypervelMigrations(array|string $database = [])

Migrate Hypervel's default migrations.

Parameters

array|string $database

Return Value

void

protected void runHypervelMigrations(array|string $database = [])

Migrate all Hypervel migrations.

Parameters

array|string $database

Return Value

void

protected array resolveHypervelMigrationsOptions(array|string $database = [])

internal  
 

No description

Parameters

array|string $database

Return Value

array

protected void resetApplicationArtisanCommands(Application $app)

No description

Parameters

Application $app

Return Value

void

at line 28
protected void reloadApplication()

Reload the application instance.

Return Value

void