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 callable $onFailure
static int $counter

Methods

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

Checks assertion. Values must be exactly the same.

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

Checks assertion. Values must not be exactly the same.

static void
equal($expected, $actual, string $description = null)

Checks assertion. The identity of objects and the order of keys in the arrays are ignored.

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

Checks assertion. The identity of objects and the order of keys in the arrays are ignored.

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

Checks assertion. Values must contains expected needle.

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

Checks assertion. Values must not contains expected needle.

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

Checks TRUE assertion.

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

Checks FALSE assertion.

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

Checks NULL assertion.

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

Checks Not a Number assertion.

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

Checks truthy assertion.

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

Checks falsey (empty) assertion.

static void
count(int $count, mixed $value, string $description = null)

Checks if subject has expected count.

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

Checks assertion.

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

Checks if the function throws exception.

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

Checks if the function throws exception, alias for exception().

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

Checks if the function generates PHP error or throws exception.

static void
noError(callable $function)

Checks that the function does not generate PHP error and does not throw exception.

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

Compares result using regular expression or mask: %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

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

Compares results using mask sorted in file.

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

Failed assertion

static 
with($obj, Closure $closure)

No description

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

Compares using mask.

static array
expandMatchingPatterns(string $pattern, $actual)

No description

Details

at line 53
static void same($expected, $actual, string $description = null)

Checks assertion. Values must be exactly the same.

Parameters

$expected
$actual
string $description

Return Value

void

at line 65
static void notSame($expected, $actual, string $description = null)

Checks assertion. Values must not be exactly the same.

Parameters

$expected
$actual
string $description

Return Value

void

at line 77
static void equal($expected, $actual, string $description = null)

Checks assertion. The identity of objects and the order of keys in the arrays are ignored.

Parameters

$expected
$actual
string $description

Return Value

void

at line 89
static void notEqual($expected, $actual, string $description = null)

Checks assertion. The identity of objects and the order of keys in the arrays are ignored.

Parameters

$expected
$actual
string $description

Return Value

void

at line 101
static void contains($needle, $actual, string $description = null)

Checks assertion. Values must contains expected needle.

Parameters

$needle
$actual
string $description

Return Value

void

at line 121
static void notContains($needle, $actual, string $description = null)

Checks assertion. Values must not contains expected needle.

Parameters

$needle
$actual
string $description

Return Value

void

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

Checks TRUE assertion.

Parameters

mixed $actual
string $description

Return Value

void

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

Checks FALSE assertion.

Parameters

mixed $actual
string $description

Return Value

void

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

Checks NULL assertion.

Parameters

mixed $actual
string $description

Return Value

void

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

Checks Not a Number assertion.

Parameters

mixed $actual
string $description

Return Value

void

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

Checks truthy assertion.

Parameters

mixed $actual
string $description

Return Value

void

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

Checks falsey (empty) assertion.

Parameters

mixed $actual
string $description

Return Value

void

at line 220
static void count(int $count, mixed $value, string $description = null)

Checks if subject has expected count.

Parameters

int $count
mixed $value
string $description

Return Value

void

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

Checks assertion.

Parameters

string|object $type
mixed $value
string $description

Return Value

void

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

Checks if the function throws exception.

Parameters

callable $function
string $class
string $message
$code

Return Value

Throwable|null

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

Checks if the function throws exception, alias for exception().

Parameters

callable $function
string $class
string $message
$code

Return Value

Throwable|null

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

Checks if the function generates PHP error or throws exception.

Parameters

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

Return Value

Throwable|null

Exceptions

Exception
Exception

at line 362
static void noError(callable $function)

Checks that the function does not generate PHP error and does not throw exception.

Parameters

callable $function

Return Value

void

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

Compares result using regular expression or mask: %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

$actual
string $description

Return Value

void

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

Compares results using mask sorted in file.

Parameters

string $file
$actual
string $description

Return Value

void

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

Failed assertion

Parameters

string $message
$actual
$expected
Throwable $previous

Return Value

void

at line 439
static with($obj, Closure $closure)

No description

Parameters

$obj
Closure $closure

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

internal  
 

Compares using mask.

Parameters

string $pattern
$actual
bool $strict

Return Value

bool

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

internal  
 

No description

Parameters

string $pattern
$actual

Return Value

array