class Assert

Provides assertion methods for verifying values in tests.

Constants

private Epsilon

used by equal() for comparing floats

Properties

static array<string,string> $patterns
static $expandPatterns

expand patterns in match() and matchFile()

static $onFailure
static $counter

Methods

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

Asserts that two values are identical (===).

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

Asserts that two values are not identical (!==).

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

Asserts that two values are equal, ignoring object identity, array key order, and tiny float differences by default.

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

Asserts that two values are not equal (same loose comparison rules as equal()).

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

Asserts that a string contains a substring, or an array contains an element (strict).

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

Asserts that a string does not contain a substring, or an array does not contain an element (strict).

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

Asserts that an array has the given key.

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

Asserts that an array does not have the given key.

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

Asserts that a value is strictly true (=== true).

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

Asserts that a value is strictly false (=== false).

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

Asserts that a value is strictly null (=== null).

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

Asserts that a value is not null (!== null).

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

Asserts that a value is NAN. Use only this method for NAN checks, as NAN !== NAN.

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

Asserts that a value is truthy (non-empty, non-zero, non-null, non-false).

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

Asserts that a value is falsy (empty string, 0, null, false, empty array).

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

Asserts that an array or Countable has the expected number of items.

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

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

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

No description

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

No description

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

No description

static void
noError(callable $function)

No description

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

Asserts that a string matches a given pattern.

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

Asserts that a string does not match a given pattern.

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

Asserts that a string matches a pattern loaded from a file.

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

Throws AssertException with given message, triggering any registered onFailure handler.

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

No description

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 identical (===).

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 identical (!==).

Parameters

mixed $expected
mixed $actual
string|null $description

Return Value

void

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

Asserts that two values are equal, ignoring object identity, array key order, and tiny float differences by default.

Parameters

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

Return Value

void

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

Asserts that two values are not equal (same loose comparison rules as equal()).

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 string contains a substring, or an array contains an element (strict).

Parameters

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

Return Value

void

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

Asserts that a string does not contain a substring, or an array does not contain an element (strict).

Parameters

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

Return Value

void

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

Asserts that an array has the given key.

Parameters

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

Return Value

void

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

Asserts that an array does not have the given key.

Parameters

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

Return Value

void

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

Asserts that a value is strictly true (=== true).

Parameters

mixed $actual
string|null $description

Return Value

void

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

Asserts that a value is strictly false (=== false).

Parameters

mixed $actual
string|null $description

Return Value

void

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

Asserts that a value is strictly null (=== null).

Parameters

mixed $actual
string|null $description

Return Value

void

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

Asserts that a value is not null (!== null).

Parameters

mixed $actual
string|null $description

Return Value

void

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

Asserts that a value is NAN. Use only this method for NAN checks, as NAN !== NAN.

Parameters

mixed $actual
string|null $description

Return Value

void

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

Asserts that a value is truthy (non-empty, non-zero, non-null, non-false).

Parameters

mixed $actual
string|null $description

Return Value

void

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

Asserts that a value is falsy (empty string, 0, null, false, empty array).

Parameters

mixed $actual
string|null $description

Return Value

void

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

Asserts that an array or Countable has the expected number of items.

Parameters

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

Return Value

void

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

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

Parameters

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

Return Value

void

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

No description

Parameters

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

Return Value

Throwable|null

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

No description

Parameters

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

Return Value

Throwable|null

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

No description

Parameters

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

Return Value

Throwable|null

at line 426
static void noError(callable $function)

No description

Parameters

callable $function

Return Value

void

at line 454
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 471
static void notMatch(string $pattern, string $actual, string|null $description = null)

Asserts that a string does not match a given pattern.

Parameters

string $pattern

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

string $actual
string|null $description

Return Value

void

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

Asserts that a string matches a pattern loaded from a file.

Parameters

string $file
string $actual
string|null $description

Return Value

void

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

Throws AssertException with given message, triggering any registered onFailure handler.

Parameters

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

Return Value

void

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

No description

Parameters

object|string $objectOrClass
Closure $closure

Return Value

mixed

at line 548
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 585
static array expandMatchingPatterns(string $pattern, string $actual)

internal  
 

No description

Parameters

string $pattern
string $actual

Return Value

array