Documentation

FileTest extends TestCase
in package

The base of every unit test that needs more than the class under test.

A test asks for what it needs and gets it without a web server, a database or a config file:

$this->bootFramework(["rootDirectory" => "sub"]);
$request = $this->request($this->input()->withUrl("http://localhost/sub/a/b"));

Everything handed out here is taken back after the test, so no test sees the settings, the request or the cached values of another one.

Table of Contents

$temporaryDirectories  : array<string|int, mixed>
testAddsAFileAndReturnsItsRow()  : void
testAddsAFileWithOnlyAReference()  : void
testCarriesNoPermissionState()  : void
testFindsAFileByItsReference()  : void
testFindsNoFileForAnUnknownReference()  : void
testHasNoReplacementWithoutReplacedBy()  : void
testHoldsTheRowItWasBuiltFrom()  : void
testIsADatabaseEntity()  : void
testLoadsTheReplacementById()  : void
testReadsASizeBeyondThirtyTwoBits()  : void
testReadsEveryFieldByItsName()  : void
testReadsTheDescribingFields()  : void
testReadsTheIdAndTheUuid()  : void
testRecordsAReplacement()  : void
testRefusesEveryReadOnceDetached()  : void
testRemovesAFileAndDetachesTheInstance()  : void
testThrowsOnAnUnknownField()  : void
testUpdatesAFileAndClearsTheFields()  : void
testUpdatesAFileWithOnlyAReference()  : void
assertThrows()  : Throwable
Asserts that the action throws exactly this class, no subclass of it, with exactly this message. expectException() accepts subclasses and a message that only contains the expected one.
bootFramework()  : ZubZet
Provides the framework instance the global helpers (zubzet(), config(), request(), ...) work on. It holds exactly the given settings: nothing is read from a config file, nothing connects, and there is no request, response, database or user until the test sets one.
callHidden()  : mixed
Calls a method that is not public. Only for logic that has no public way in; a test goes through the public method wherever there is one.
currentUser()  : User
Makes a user without database access the current one, the one user() returns. Its constructor would identify it through the database, so it is left out: the user is anonymous unless the test says otherwise.
inDirectory()  : mixed
Runs the action with the given directory as the working directory, for code that reads relative paths. The previous directory is restored afterwards, also when the action throws.
input()  : State
An input without any data. The with...() methods of the state fill it:
removeSetting()  : void
Removes a setting, as if its line was missing in the config file.
request()  : Request
Makes the given input the current request, the one request() returns.
requireArgon2id()  : void
Skips the test on a PHP built without Argon2. The framework hashes with PASSWORD_ARGON2ID unconditionally and composer.json does not require the support, so the tests that reach it have to tolerate its absence.
response()  : Response
Makes a new response the current one, the one response() returns.
setHiddenStatic()  : void
Sets a static property that is not public. Only for state a class keeps for the whole process and offers no way to reset.
setSettings()  : void
Changes single settings of the booted framework and keeps the others.
setUp()  : void
tearDown()  : void
temporaryDirectory()  : string
An empty directory with a trailing slash, removed after the test.
clearEndpoint()  : void
clearRuntimeCaches()  : void
file()  : File
models()  : object
Puts stand-ins for the z_file and z_permission models in the model cache, so a File reads its rows from the given list instead of a database. The model lookup finds them without a file on disk.
row()  : array<string|int, mixed>

Properties

$temporaryDirectories

private array<string|int, mixed> $temporaryDirectories = []

Methods

testAddsAFileAndReturnsItsRow()

public testAddsAFileAndReturnsItsRow() : void
Return values
void —

testAddsAFileWithOnlyAReference()

public testAddsAFileWithOnlyAReference() : void
Return values
void —

testCarriesNoPermissionState()

public testCarriesNoPermissionState() : void
Return values
void —

testFindsAFileByItsReference()

public testFindsAFileByItsReference() : void
Return values
void —

testFindsNoFileForAnUnknownReference()

public testFindsNoFileForAnUnknownReference() : void
Return values
void —

testHasNoReplacementWithoutReplacedBy()

public testHasNoReplacementWithoutReplacedBy() : void
Return values
void —

testHoldsTheRowItWasBuiltFrom()

public testHoldsTheRowItWasBuiltFrom() : void
Return values
void —

testIsADatabaseEntity()

public testIsADatabaseEntity() : void
Return values
void —

testLoadsTheReplacementById()

public testLoadsTheReplacementById() : void
Return values
void —

testReadsASizeBeyondThirtyTwoBits()

public testReadsASizeBeyondThirtyTwoBits() : void
Return values
void —

testReadsEveryFieldByItsName()

public testReadsEveryFieldByItsName() : void
Return values
void —

testReadsTheDescribingFields()

public testReadsTheDescribingFields() : void
Return values
void —

testReadsTheIdAndTheUuid()

public testReadsTheIdAndTheUuid() : void
Return values
void —

testRecordsAReplacement()

public testRecordsAReplacement() : void
Return values
void —

testRefusesEveryReadOnceDetached()

public testRefusesEveryReadOnceDetached() : void
Return values
void —

testRemovesAFileAndDetachesTheInstance()

public testRemovesAFileAndDetachesTheInstance() : void
Return values
void —

testThrowsOnAnUnknownField()

public testThrowsOnAnUnknownField() : void
Return values
void —

testUpdatesAFileAndClearsTheFields()

public testUpdatesAFileAndClearsTheFields() : void
Return values
void —

testUpdatesAFileWithOnlyAReference()

public testUpdatesAFileWithOnlyAReference() : void
Return values
void —

assertThrows()

Asserts that the action throws exactly this class, no subclass of it, with exactly this message. expectException() accepts subclasses and a message that only contains the expected one.

protected assertThrows(class-string<\Throwable> $class, string $message, callable $action) : Throwable
Parameters
$class : class-string<\Throwable>
$message : string
$action : callable
Return values
Throwable —

bootFramework()

Provides the framework instance the global helpers (zubzet(), config(), request(), ...) work on. It holds exactly the given settings: nothing is read from a config file, nothing connects, and there is no request, response, database or user until the test sets one.

protected bootFramework([array<string, mixed> $settings = [] ]) : ZubZet
Parameters
$settings : array<string, mixed> = []

What config() returns

Return values
ZubZet —

callHidden()

Calls a method that is not public. Only for logic that has no public way in; a test goes through the public method wherever there is one.

protected callHidden(object|class-string $target, string $method, mixed ...$arguments) : mixed
Parameters
$target : object|class-string

An object, or a class name for a static method

$method : string
$arguments : mixed
Return values
mixed —

currentUser()

Makes a user without database access the current one, the one user() returns. Its constructor would identify it through the database, so it is left out: the user is anonymous unless the test says otherwise.

protected currentUser([bool $loggedIn = false ]) : User
Parameters
$loggedIn : bool = false
Return values
User —

inDirectory()

Runs the action with the given directory as the working directory, for code that reads relative paths. The previous directory is restored afterwards, also when the action throws.

protected inDirectory(string $directory, callable $action) : mixed
Parameters
$directory : string
$action : callable
Return values
mixed —

input()

An input without any data. The with...() methods of the state fill it:

protected input([string $requestOrder = "GPC" ]) : State

$this->input()->withMethod("POST")->withPost(["name" => "value"])

REQUEST is put together from GET, POST and COOKIE in the given order, whatever the php.ini of the machine says, so a test sees the same REQUEST everywhere.

Parameters
$requestOrder : string = "GPC"
Return values
State —

removeSetting()

Removes a setting, as if its line was missing in the config file.

protected removeSetting(string $key) : void
Parameters
$key : string
Return values
void —

request()

Makes the given input the current request, the one request() returns.

protected request([State|null $input = null ]) : Request

Boots the framework without settings when the test has not done so.

Parameters
$input : State|null = null
Return values
Request —

requireArgon2id()

Skips the test on a PHP built without Argon2. The framework hashes with PASSWORD_ARGON2ID unconditionally and composer.json does not require the support, so the tests that reach it have to tolerate its absence.

protected requireArgon2id() : void
Return values
void —

response()

Makes a new response the current one, the one response() returns.

protected response() : Response

Boots the framework without settings when the test has not done so.

Return values
Response —

setHiddenStatic()

Sets a static property that is not public. Only for state a class keeps for the whole process and offers no way to reset.

protected setHiddenStatic(class-string $class, string $property, mixed $value) : void
Parameters
$class : class-string
$property : string
$value : mixed
Return values
void —

setSettings()

Changes single settings of the booted framework and keeps the others.

protected setSettings(array<string, mixed> $settings) : void
Parameters
$settings : array<string, mixed>
Return values
void —

setUp()

protected setUp() : void
Return values
void —

tearDown()

protected tearDown() : void
Return values
void —

temporaryDirectory()

An empty directory with a trailing slash, removed after the test.

protected temporaryDirectory() : string
Return values
string —

clearEndpoint()

private clearEndpoint() : void
Return values
void —

clearRuntimeCaches()

private clearRuntimeCaches() : void
Return values
void —

file()

private file([array<string, mixed> $overrides = [] ]) : File
Parameters
$overrides : array<string, mixed> = []
Return values
File —

models()

Puts stand-ins for the z_file and z_permission models in the model cache, so a File reads its rows from the given list instead of a database. The model lookup finds them without a file on disk.

private models(array<int, array<string|int, mixed>> $rows) : object
Parameters
$rows : array<int, array<string|int, mixed>>

The z_file rows by id

Return values
object —

row()

private row([array<string, mixed> $overrides = [] ]) : array<string|int, mixed>
Parameters
$overrides : array<string, mixed> = []
Return values
array<string|int, mixed> —

Search results