Assert
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
Asserts that two values are equal and have the same type and identity of objects.
Asserts that two values are not equal or do not have the same type and identity of objects.
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.
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.
Asserts that a haystack (string or array) contains an expected needle.
Asserts that a haystack (string or array) does not contain an expected needle.
Asserts that a haystack has an expected key.
Asserts that a haystack doesn't have an expected key.
Asserts that a value is true.
Asserts that a value is false.
Asserts that a value is null.
Asserts that a value is not null.
Asserts that a value is Not a Number.
Asserts that a value is truthy.
Asserts that a value is falsey.
Asserts the number of items in an array or Countable.
Asserts that a value is of given class, interface or built-in type.
Asserts that a function throws exception of given type and its message matches given pattern.
Asserts that a function throws exception of given type and its message matches given pattern. Alias for exception().
Asserts that a function generates one or more PHP errors or throws exceptions.
Asserts that a function does not generate PHP errors and does not throw exceptions.
Asserts that a string matches a given pattern.
Asserts that a string matches a given pattern stored in file.
Assertion that fails.
Compares using mask.
No description
Details
at line 57
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.
at line 69
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.
at line 82
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.
at line 101
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.
at line 118
static void
contains(mixed $needle, array|string $actual, string|null $description = null)
Asserts that a haystack (string or array) contains an expected needle.
at line 137
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.
at line 156
static void
hasKey(string|int $key, array $actual, string|null $description = null)
Asserts that a haystack has an expected key.
at line 168
static void
hasNotKey(string|int $key, array $actual, string|null $description = null)
Asserts that a haystack doesn't have an expected key.
at line 180
static void
true(mixed $actual, string|null $description = null)
Asserts that a value is true.
at line 192
static void
false(mixed $actual, string|null $description = null)
Asserts that a value is false.
at line 204
static void
null(mixed $actual, string|null $description = null)
Asserts that a value is null.
at line 216
static void
notNull(mixed $actual, string|null $description = null)
Asserts that a value is not null.
at line 228
static void
nan(mixed $actual, string|null $description = null)
Asserts that a value is Not a Number.
at line 240
static void
truthy(mixed $actual, string|null $description = null)
Asserts that a value is truthy.
at line 252
static void
falsey(mixed $actual, string|null $description = null)
Asserts that a value is falsey.
at line 264
static void
count(int $count, array|Countable $value, string|null $description = null)
Asserts the number of items in an array or Countable.
at line 276
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.
at line 300
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.
at line 334
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().
at line 349
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.
at line 411
static void
noError(callable $function)
Asserts that a function does not generate PHP errors and does not throw exceptions.
at line 439
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 455
static void
matchFile(string $file, string $actual, string|null $description = null)
Asserts that a string matches a given pattern stored in file.
at line 475
static void
fail(string $message, $actual = null, $expected = null, Throwable|null $previous = null, string|null $outputName = null)
Assertion that fails.
at line 502
static mixed
with(object|string $objectOrClass, Closure $closure)
Executes function that can access private and protected members of given object via $this.
at line 515
static bool
isMatching(string $pattern, string $actual, bool $strict = false)
internal |
Compares using mask.
at line 550
static array
expandMatchingPatterns(string $pattern, string $actual)
internal |
No description