class Assert

Assertion test helpers.

Constants

private Epsilon

used by equal() for comparing floats

Properties

static $patterns

used by match(); in values, each $ followed by number is backreference

static $expandPatterns

expand patterns in match() and matchFile()

static callable $onFailure
static $counter

Methods

static void
same(mixed $expected, mixed $actual, string|null $description = null)

Asserts that two values are equal and have the same type and identity of objects.

static void
notSame(mixed $expected, mixed $actual, string|null $description = null)

Asserts that two values are not equal or do not have the same type and identity of objects.

static void
equal(mixed $expected, mixed $actual, string|null $description = null, bool $matchOrder = false, bool $matchIdentity = false)

Asserts that two values are equal and checks expectations. The identity of objects, the order of keys in the arrays and marginally different floats are ignored by default.

static void
notEqual(mixed $expected, mixed $actual, string|null $description = null)

Asserts that two values are not equal and checks expectations. The identity of objects, the order of keys in the arrays and marginally different floats are ignored.

static void
contains(mixed $needle, array|string $actual, string|null $description = null)

Asserts that a haystack (string or array) contains an expected needle.

static void
notContains(mixed $needle, array|string $actual, string|null $description = null)

Asserts that a haystack (string or array) does not contain an expected needle.

static void
hasKey(string|int $key, array $actual, string|null $description = null)

Asserts that a haystack has an expected key.

static void
hasNotKey(string|int $key, array $actual, string|null $description = null)

Asserts that a haystack doesn't have an expected key.

static void
true(mixed $actual, string|null $description = null)

Asserts that a value is true.

static void
false(mixed $actual, string|null $description = null)

Asserts that a value is false.

static void
null(mixed $actual, string|null $description = null)

Asserts that a value is null.

static void
notNull(mixed $actual, string|null $description = null)

Asserts that a value is not null.

static void
nan(mixed $actual, string|null $description = null)

Asserts that a value is Not a Number.

static void
truthy(mixed $actual, string|null $description = null)

Asserts that a value is truthy.

static void
falsey(mixed $actual, string|null $description = null)

Asserts that a value is falsey.

static void
count(int $count, array|Countable $value, string|null $description = null)

Asserts the number of items in an array or Countable.

static void
type(string|object $type, mixed $value, string|null $description = null)

Asserts that a value is of given class, interface or built-in type.

static Throwable|null
exception(callable $function, string $class, string|null $message = null, $code = null)

Asserts that a function throws exception of given type and its message matches given pattern.

static Throwable|null
throws(callable $function, string $class, string|null $message = null, mixed $code = null)

Asserts that a function throws exception of given type and its message matches given pattern. Alias for exception().

static Throwable|null
error(callable $function, int|string|array $expectedType, string|null $expectedMessage = null)

Asserts that a function generates one or more PHP errors or throws exceptions.

static void
noError(callable $function)

Asserts that a function does not generate PHP errors and does not throw exceptions.

static void
match(string $pattern, string $actual, string|null $description = null)

Asserts that a string matches a given pattern.

static void
matchFile(string $file, string $actual, string|null $description = null)

Asserts that a string matches a given pattern stored in file.

static void
fail(string $message, $actual = null, $expected = null, Throwable|null $previous = null, string|null $outputName = null)

Assertion that fails.

static mixed
with(object|string $objectOrClass, Closure $closure)

Executes function that can access private and protected members of given object via $this.

static bool
isMatching(string $pattern, string $actual, bool $strict = false)

Compares using mask.

static array
expandMatchingPatterns(string $pattern, string $actual)

No description

Details

at line 54
static void same(mixed $expected, mixed $actual, string|null $description = null)

Asserts that two values are equal and have the same type and identity of objects.

Parameters

mixed $expected
mixed $actual
string|null $description

Return Value

void

at line 66
static void notSame(mixed $expected, mixed $actual, string|null $description = null)

Asserts that two values are not equal or do not have the same type and identity of objects.

Parameters

mixed $expected
mixed $actual
string|null $description

Return Value

void

at line 79
static void equal(mixed $expected, mixed $actual, string|null $description = null, bool $matchOrder = false, bool $matchIdentity = false)

Asserts that two values are equal and checks expectations. The identity of objects, the order of keys in the arrays and marginally different floats are ignored by default.

Parameters

mixed $expected
mixed $actual
string|null $description
bool $matchOrder
bool $matchIdentity

Return Value

void

at line 98
static void notEqual(mixed $expected, mixed $actual, string|null $description = null)

Asserts that two values are not equal and checks expectations. The identity of objects, the order of keys in the arrays and marginally different floats are ignored.

Parameters

mixed $expected
mixed $actual
string|null $description

Return Value

void

at line 115
static void contains(mixed $needle, array|string $actual, string|null $description = null)

Asserts that a haystack (string or array) contains an expected needle.

Parameters

mixed $needle
array|string $actual
string|null $description

Return Value

void

at line 134
static void notContains(mixed $needle, array|string $actual, string|null $description = null)

Asserts that a haystack (string or array) does not contain an expected needle.

Parameters

mixed $needle
array|string $actual
string|null $description

Return Value

void

at line 153
static void hasKey(string|int $key, array $actual, string|null $description = null)

Asserts that a haystack has an expected key.

Parameters

string|int $key
array $actual
string|null $description

Return Value

void

at line 165
static void hasNotKey(string|int $key, array $actual, string|null $description = null)

Asserts that a haystack doesn't have an expected key.

Parameters

string|int $key
array $actual
string|null $description

Return Value

void

at line 177
static void true(mixed $actual, string|null $description = null)

Asserts that a value is true.

Parameters

mixed $actual
string|null $description

Return Value

void

at line 189
static void false(mixed $actual, string|null $description = null)

Asserts that a value is false.

Parameters

mixed $actual
string|null $description

Return Value

void

at line 201
static void null(mixed $actual, string|null $description = null)

Asserts that a value is null.

Parameters

mixed $actual
string|null $description

Return Value

void

at line 213
static void notNull(mixed $actual, string|null $description = null)

Asserts that a value is not null.

Parameters

mixed $actual
string|null $description

Return Value

void

at line 225
static void nan(mixed $actual, string|null $description = null)

Asserts that a value is Not a Number.

Parameters

mixed $actual
string|null $description

Return Value

void

at line 237
static void truthy(mixed $actual, string|null $description = null)

Asserts that a value is truthy.

Parameters

mixed $actual
string|null $description

Return Value

void

at line 249
static void falsey(mixed $actual, string|null $description = null)

Asserts that a value is falsey.

Parameters

mixed $actual
string|null $description

Return Value

void

at line 261
static void count(int $count, array|Countable $value, string|null $description = null)

Asserts the number of items in an array or Countable.

Parameters

int $count
array|Countable $value
string|null $description

Return Value

void

at line 273
static void type(string|object $type, mixed $value, string|null $description = null)

Asserts that a value is of given class, interface or built-in type.

Parameters

string|object $type
mixed $value
string|null $description

Return Value

void

at line 297
static Throwable|null exception(callable $function, string $class, string|null $message = null, $code = null)

Asserts that a function throws exception of given type and its message matches given pattern.

Parameters

callable $function
string $class
string|null $message
$code

Return Value

Throwable|null

at line 331
static Throwable|null throws(callable $function, string $class, string|null $message = null, mixed $code = null)

Asserts that a function throws exception of given type and its message matches given pattern. Alias for exception().

Parameters

callable $function
string $class
string|null $message
mixed $code

Return Value

Throwable|null

at line 346
static Throwable|null error(callable $function, int|string|array $expectedType, string|null $expectedMessage = null)

Asserts that a function generates one or more PHP errors or throws exceptions.

Parameters

callable $function
int|string|array $expectedType
string|null $expectedMessage

Return Value

Throwable|null

Exceptions

Exception

at line 408
static void noError(callable $function)

Asserts that a function does not generate PHP errors and does not throw exceptions.

Parameters

callable $function

Return Value

void

at line 436
static void match(string $pattern, string $actual, string|null $description = null)

Asserts that a string matches a given pattern.

%a% one or more of anything except the end of line characters %a?% zero or more of anything except the end of line characters %A% one or more of anything including the end of line characters %A?% zero or more of anything including the end of line characters %s% one or more white space characters except the end of line characters %s?% zero or more white space characters except the end of line characters %S% one or more of characters except the white space %S?% zero or more of characters except the white space %c% a single character of any sort (except the end of line) %d% one or more digits %d?% zero or more digits %i% signed integer value %f% floating point number %h% one or more HEX digits

Parameters

string $pattern

mask|regexp; only delimiters ~ and # are supported for regexp

string $actual
string|null $description

Return Value

void

at line 452
static void matchFile(string $file, string $actual, string|null $description = null)

Asserts that a string matches a given pattern stored in file.

Parameters

string $file
string $actual
string|null $description

Return Value

void

at line 472
static void fail(string $message, $actual = null, $expected = null, Throwable|null $previous = null, string|null $outputName = null)

Assertion that fails.

Parameters

string $message
$actual
$expected
Throwable|null $previous
string|null $outputName

Return Value

void

at line 499
static mixed with(object|string $objectOrClass, Closure $closure)

Executes function that can access private and protected members of given object via $this.

Parameters

object|string $objectOrClass
Closure $closure

Return Value

mixed

at line 512
static bool isMatching(string $pattern, string $actual, bool $strict = false)

internal  
 

Compares using mask.

Parameters

string $pattern
string $actual
bool $strict

Return Value

bool

at line 547
static array expandMatchingPatterns(string $pattern, string $actual)

internal  
 

No description

Parameters

string $pattern
string $actual

Return Value

array