trait InteractsWithSqliteDatabaseFile

Traits

Provides assertion helpers and cleanup utilities for testing file publishing.

Properties

protected bool $interactsWithPublishedFilesTeardownRegistered

Determine if trait teardown has been registered.

from  InteractsWithPublishedFiles
protected null|array<int, string> $cachedExistingMigrationsFiles

List of existing migration files.

from  InteractsWithPublishedFiles
protected array<int, string> $files

List of generated files.

Methods

void
setUpInteractsWithPublishedFiles()

Setup Interacts with Published Files environment.

void
tearDownInteractsWithPublishedFiles()

Teardown Interacts with Published Files environment.

void
cacheExistingMigrationsFiles()

Cache existing migration files.

void
assertFileContains(array $contains, string $file, string $message = '')

Assert file contains the given strings.

void
assertFileDoesNotContains(array $contains, string $file, string $message = '')

Assert file does not contain the given strings.

void
assertFileNotContains(array $contains, string $file, string $message = '')

Assert file does not contain the given strings.

void
assertMigrationFileContains(array $contains, string $file, string $message = '', string|null $directory = null)

Assert migration file contains the given strings.

void
assertMigrationFileDoesNotContains(array $contains, string $file, string $message = '', string|null $directory = null)

Assert migration file does not contain the given strings.

void
assertMigrationFileNotContains(array $contains, string $file, string $message = '', string|null $directory = null)

Assert migration file does not contain the given strings.

void
assertFilenameExists(string $file)

Assert filename exists.

void
assertFilenameDoesNotExists(string $file)

Assert filename does not exist.

void
assertFilenameNotExists(string $file)

Assert filename does not exist.

void
assertMigrationFileExists(string $file, string|null $directory = null)

Assert migration filename exists.

void
assertMigrationFileDoesNotExists(string $file, string|null $directory = null)

Assert migration filename does not exist.

void
assertMigrationFileNotExists(string $file, string|null $directory = null)

Assert migration filename does not exist.

void
cleanUpPublishedFiles()

Removes generated files.

string|null
findFirstPublishedMigrationFile(string $filename, string|null $directory = null)

Find the first published migration file matching the filename.

void
cleanUpPublishedMigrationFiles()

Removes generated migration files.

string
publishedFilePath(string|SplFileInfo $file)

Normalize a published file entry into a filesystem path.

void
purgeSqliteConnection()

Purge the sqlite connection before swapping the runtime database file.

string
baseSqliteDatabasePath()

Get the base sqlite database path before any parallel suffix is applied.

string
activeSqliteDatabasePath()

Get the sqlite database path used by remote CLI commands in parallel.

void
useActiveSqliteDatabasePath(callable $callback)

Temporarily point the sqlite connection at the active runtime database file.

void
withoutSqliteDatabase(callable $callback)

Drop Sqlite database.

void
withSqliteDatabase(callable $callback)

Drop and create a new Sqlite database.

static void
cleanupBackupSqliteDatabaseFilesOnFailed()

Clean up backup Sqlite database files after class teardown.

Details

protected void setUpInteractsWithPublishedFiles()

internal  
 

Setup Interacts with Published Files environment.

Return Value

void

protected void tearDownInteractsWithPublishedFiles()

internal  
 

Teardown Interacts with Published Files environment.

Return Value

void

protected void cacheExistingMigrationsFiles()

internal  
 

Cache existing migration files.

Return Value

void

protected void assertFileContains(array $contains, string $file, string $message = '')

Assert file contains the given strings.

Parameters

array $contains
string $file
string $message

Return Value

void

protected void assertFileDoesNotContains(array $contains, string $file, string $message = '')

Assert file does not contain the given strings.

Parameters

array $contains
string $file
string $message

Return Value

void

protected void assertFileNotContains(array $contains, string $file, string $message = '')

Assert file does not contain the given strings.

Parameters

array $contains
string $file
string $message

Return Value

void

protected void assertMigrationFileContains(array $contains, string $file, string $message = '', string|null $directory = null)

Assert migration file contains the given strings.

Parameters

array $contains
string $file
string $message
string|null $directory

Return Value

void

protected void assertMigrationFileDoesNotContains(array $contains, string $file, string $message = '', string|null $directory = null)

Assert migration file does not contain the given strings.

Parameters

array $contains
string $file
string $message
string|null $directory

Return Value

void

protected void assertMigrationFileNotContains(array $contains, string $file, string $message = '', string|null $directory = null)

Assert migration file does not contain the given strings.

Parameters

array $contains
string $file
string $message
string|null $directory

Return Value

void

protected void assertFilenameExists(string $file)

Assert filename exists.

Parameters

string $file

Return Value

void

protected void assertFilenameDoesNotExists(string $file)

Assert filename does not exist.

Parameters

string $file

Return Value

void

protected void assertFilenameNotExists(string $file)

Assert filename does not exist.

Parameters

string $file

Return Value

void

protected void assertMigrationFileExists(string $file, string|null $directory = null)

Assert migration filename exists.

Parameters

string $file
string|null $directory

Return Value

void

protected void assertMigrationFileDoesNotExists(string $file, string|null $directory = null)

Assert migration filename does not exist.

Parameters

string $file
string|null $directory

Return Value

void

protected void assertMigrationFileNotExists(string $file, string|null $directory = null)

Assert migration filename does not exist.

Parameters

string $file
string|null $directory

Return Value

void

protected void cleanUpPublishedFiles()

internal  
 

Removes generated files.

Return Value

void

protected string|null findFirstPublishedMigrationFile(string $filename, string|null $directory = null)

Find the first published migration file matching the filename.

Parameters

string $filename
string|null $directory

Return Value

string|null

protected void cleanUpPublishedMigrationFiles()

internal  
 

Removes generated migration files.

Return Value

void

protected string publishedFilePath(string|SplFileInfo $file)

Normalize a published file entry into a filesystem path.

Parameters

string|SplFileInfo $file

Return Value

string

at line 33
protected void purgeSqliteConnection()

Purge the sqlite connection before swapping the runtime database file.

These helpers replace database.sqlite on disk while the parent test process and remote CLI commands share the same runtime base path. The testing resolver caches sqlite connections per worker, so the parent process must drop its cached PDO handle before reading a newly swapped file.

Return Value

void

at line 41
protected string baseSqliteDatabasePath()

Get the base sqlite database path before any parallel suffix is applied.

Return Value

string

at line 65
protected string activeSqliteDatabasePath()

Get the sqlite database path used by remote CLI commands in parallel.

The commander subprocess boots a fresh Testbench application. When DB_CONNECTION=sqlite and ParaTest sets TEST_TOKEN, Testbench rewrites the sqlite database path to a token-suffixed file. The parent test process must point its sqlite connection at that same file before asserting on it.

Return Value

string

at line 80
protected void useActiveSqliteDatabasePath(callable $callback)

Temporarily point the sqlite connection at the active runtime database file.

Parameters

callable $callback

Return Value

void

at line 108
protected void withoutSqliteDatabase(callable $callback)

Drop Sqlite database.

Parameters

callable $callback

Return Value

void

at line 160
protected void withSqliteDatabase(callable $callback)

Drop and create a new Sqlite database.

Parameters

callable $callback

Return Value

void

at line 200
static void cleanupBackupSqliteDatabaseFilesOnFailed()

Clean up backup Sqlite database files after class teardown.

Return Value

void