Assert
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
Asserts that two values are identical (===).
Asserts that two values are not identical (!==).
Asserts that two values are equal, ignoring object identity, array key order, and tiny float differences by default.
Asserts that two values are not equal (same loose comparison rules as equal()).
Asserts that a string contains a substring, or an array contains an element (strict).
Asserts that a string does not contain a substring, or an array does not contain an element (strict).
Asserts that an array has the given key.
Asserts that an array does not have the given key.
Asserts that a value is strictly true (=== true).
Asserts that a value is strictly false (=== false).
Asserts that a value is strictly null (=== null).
Asserts that a value is not null (!== null).
Asserts that a value is NAN. Use only this method for NAN checks, as NAN !== NAN.
Asserts that a value is truthy (non-empty, non-zero, non-null, non-false).
Asserts that a value is falsy (empty string, 0, null, false, empty array).
Asserts that an array or Countable has the expected number of items.
Asserts that a value is of the given built-in type, class, or interface.
No description
No description
No description
No description
Asserts that a string matches a given pattern.
Asserts that a string does not match a given pattern.
Asserts that a string matches a pattern loaded from a file.
Throws AssertException with given message, triggering any registered onFailure handler.
Compares using mask.
No description
Details
at line 54
static void
same(mixed $expected, mixed $actual, string|null $description = null)
Asserts that two values are identical (===).
at line 66
static void
notSame(mixed $expected, mixed $actual, string|null $description = null)
Asserts that two values are not identical (!==).
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.
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()).
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).
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).
at line 155
static void
hasKey(string|int $key, array $actual, string|null $description = null)
Asserts that an array has the given key.
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.
at line 180
static void
true(mixed $actual, string|null $description = null)
Asserts that a value is strictly true (=== true).
at line 192
static void
false(mixed $actual, string|null $description = null)
Asserts that a value is strictly false (=== false).
at line 204
static void
null(mixed $actual, string|null $description = null)
Asserts that a value is strictly null (=== null).
at line 216
static void
notNull(mixed $actual, string|null $description = null)
Asserts that a value is not null (!== null).
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.
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).
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).
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.
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.
at line 305
static Throwable|null
exception(callable $function, string $class, string|null $message = null, int|string|null $code = null)
No description
at line 343
static Throwable|null
throws(callable $function, string $class, string|null $message = null, mixed $code = null)
No description
at line 360
static Throwable|null
error(callable $function, int|string|array $expectedType, string|null $expectedMessage = null)
No description
at line 426
static void
noError(callable $function)
No description
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
at line 471
static void
notMatch(string $pattern, string $actual, string|null $description = null)
Asserts that a string does not match a given pattern.
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.
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.
at line 535
static mixed
with(object|string $objectOrClass, Closure $closure)
No description
at line 548
static bool
isMatching(string $pattern, string $actual, bool $strict = false)
| internal |
Compares using mask.
at line 585
static array
expandMatchingPatterns(string $pattern, string $actual)
| internal |
No description