| layout | doc |
|---|---|
| title | Asserts - Codeception - Documentation |
{% highlight yaml %} composer require --dev codeception/module-asserts
{% endhighlight %}
Special module for using asserts in your tests.
param string|int$keyparam \ArrayAccess|array$arrayparam string$messagereturn void
Asserts that an array has a specified key.
param string|int$keyparam \ArrayAccess|array$arrayparam string$messagereturn void
Asserts that an array does not have a specified key.
param string$attributeNameparam class-string$classNameparam string$messagereturn void
Asserts that a class has a specified attribute.
param string$attributeNameparam class-string$classNameparam string$messagereturn void
Asserts that a class has a specified static attribute.
param string$attributeNameparam class-string$classNameparam string$messagereturn void
Asserts that a class does not have a specified attribute.
param string$attributeNameparam class-string$classNameparam string$messagereturn void
Asserts that a class does not have a specified static attribute.
param mixed$needleparam iterable<mixed>$haystackparam string$messagereturn void
Asserts that a haystack contains a needle.
param mixed$needleparam iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param class-string$classNameparam iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param string$typeparam iterable<mixed>$haystackparam ?bool$isNativeTypeparam string$messagereturn void
Asserts that a haystack contains only values of a given type.
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param class-string$classNameparam iterable<mixed>$haystackparam string$messagereturn void
Asserts that a haystack contains only instances of a given class name.
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param iterable<mixed>$haystackparam string$messagereturn void
param int$expectedCountparam \Countable|iterable<mixed>$haystackparam string$messagereturn void
Asserts the number of elements of an array, Countable or Traversable.
param string$directoryparam string$messagereturn void
Asserts that a directory does not exist.
param string$directoryparam string$messagereturn void
Asserts that a directory exists.
param string$directoryparam string$messagereturn void
Asserts that a directory exists and is not readable.
param string$directoryparam string$messagereturn void
Asserts that a directory exists and is not writable.
param string$directoryparam string$messagereturn void
Asserts that a directory exists and is readable.
param string$directoryparam string$messagereturn void
Asserts that a directory exists and is writable.
param string$patternparam string$stringparam string$messagereturn void
Asserts that a string does not match a given regular expression.
phpstan-assertempty $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is empty.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are equal.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are equal (canonicalizing).
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are equal (ignoring case).
param mixed$expectedparam mixed$actualparam float$deltaparam string$messagereturn void
Asserts that two variables are equal (with delta).
phpstan-assertfalse $conditionparam mixed$conditionparam string$messagereturn void
Asserts that a condition is false.
param string$filenameparam string$messagereturn void
Asserts that a file does not exist.
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is equal to the contents of another file.
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is equal to the contents of another file (canonicalizing).
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is equal to the contents of another file (ignoring case).
param string$filenameparam string$messagereturn void
Asserts that a file exists.
param string$fileparam string$messagereturn void
Asserts that a file exists and is not readable.
param string$fileparam string$messagereturn void
Asserts that a file exists and is not writable.
param string$fileparam string$messagereturn void
Asserts that a file exists and is readable.
param string$fileparam string$messagereturn void
Asserts that a file exists and is writable.
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is not equal to the contents of another file.
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is not equal to the contents of another file (canonicalizing).
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is not equal to the contents of another file (ignoring case).
param string$filenameparam string$messagereturn void
Asserts that a file does not exist.
param mixed$actualparam string$messagereturn void
Asserts that a variable is finite.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is greater than or equal to another value.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is greater than another value.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is greater than or equal to another value.
param mixed$actualparam string$messagereturn void
Asserts that a variable is infinite.
templateExpectedType of objectphpstan-assert=ExpectedType $actualparam class-string<ExpectedType>$expectedparam mixed$actualparam string$messagereturn void
Asserts that a variable is of a given type.
phpstan-assertarray $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type array.
phpstan-assertbool $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type bool.
phpstan-assertcallable $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type callable.
phpstan-assertresource $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type resource and is closed.
param mixed$actualparam string$messagereturn void
Asserts that a variable is empty.
phpstan-assertfloat $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type float.
phpstan-assertint $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type int.
phpstan-assertiterable $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type iterable.
phpstan-assert!array $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type array.
phpstan-assert!bool $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type bool.
phpstan-assert!callable $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type callable.
phpstan-assert!resource $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type resource.
phpstan-assert!float $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type float.
phpstan-assert!int $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type int.
phpstan-assert!iterable $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type iterable.
phpstan-assert!numeric $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type numeric.
phpstan-assert!object $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type object.
param string$filenameparam string$messagereturn void
Asserts that a file/dir exists and is not readable.
phpstan-assert!resource $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type resource.
psalm-assert!scalar $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type scalar.
phpstan-assert!string $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type string.
param string$filenameparam string$messagereturn void
Asserts that a file/dir exists and is not writable.
phpstan-assertnumeric $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type numeric.
phpstan-assertobject $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type object.
param string$filenameparam string$messagereturn void
Asserts that a file/dir is readable.
phpstan-assertresource $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type resource.
phpstan-assertscalar $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type scalar.
phpstan-assertstring $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type string.
param string$filenameparam string$messagereturn void
Asserts that a file/dir exists and is writable.
param string$actualJsonparam string$messagereturn void
Asserts that a string is a valid JSON string.
param string$expectedFileparam string$actualFileparam string$messagereturn void
Asserts that two JSON files are equal.
param string$expectedFileparam string$actualFileparam string$messagereturn void
Asserts that two JSON files are not equal.
param string$expectedFileparam string$actualJsonparam string$messagereturn void
Asserts that the generated JSON encoded object and the content of the given file are equal.
param string$expectedJsonparam string$actualJsonparam string$messagereturn void
Asserts that two given JSON encoded objects or arrays are equal.
param string$expectedFileparam string$actualJsonparam string$messagereturn void
Asserts that the generated JSON encoded object and the content of the given file are not equal.
param string$expectedJsonparam string$actualJsonparam string$messagereturn void
Asserts that two given JSON encoded objects or arrays are not equal.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is smaller than or equal to another value.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is smaller than another value.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is smaller than or equal to another value.
param string$patternparam string$stringparam string$messagereturn void
Asserts that a string matches a given regular expression.
param mixed$actualparam string$messagereturn void
Asserts that a variable is nan.
param mixed$needleparam iterable<mixed>$haystackparam string$messagereturn void
Asserts that a haystack does not contain a needle.
param mixed$needleparam iterable<mixed>$haystackparam string$messagereturn void
param string$typeparam iterable<mixed>$haystackparam ?bool$isNativeTypeparam string$messagereturn void
Asserts that a haystack does not contain only values of a given type.
param int$expectedCountparam \Countable|iterable<mixed>$haystackparam string$messagereturn void
Asserts the number of elements of an array, Countable or Traversable.
phpstan-assert!empty $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not empty.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are not equal.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are not equal (canonicalizing).
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are not equal (ignoring case).
param mixed$expectedparam mixed$actualparam float$deltaparam string$messagereturn void
Asserts that two variables are not equal (with delta).
phpstan-assert!false $conditionparam mixed$conditionparam string$messagereturn void
Asserts that a condition is not false.
templateExpectedType of objectphpstan-assert!ExpectedType $actualparam class-string<ExpectedType>$expectedparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of a given type.
phpstan-assert!null $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not null.
param string$patternparam string$stringparam string$messagereturn void
Asserts that a string does not match a given regular expression.
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables do not have the same type and value.
param \Countable|iterable<mixed>$expectedparam \Countable|iterable<mixed>$actualparam string$messagereturn void
Assert that the size of two arrays (or Countable or Traversable objects) is not the same.
phpstan-assert!true $conditionparam mixed$conditionparam string$messagereturn void
Asserts that a condition is not true.
phpstan-assertnull $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is null.
param string$attributeNameparam object$objectparam string$messagereturn void
Asserts that an object has a specified attribute.
param string$attributeNameparam object$objectparam string$messagereturn void
Asserts that an object does not have a specified attribute.
param string$patternparam string$stringparam string$messagereturn void
Asserts that a string matches a given regular expression.
templateExpectedTypephpstan-assert=ExpectedType $actualparam ExpectedType$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables have the same type and value.
Used on objects, it asserts that two variables reference the same object.
param \Countable|iterable<mixed>$expectedparam \Countable|iterable<mixed>$actualparam string$messagereturn void
Assert that the size of two arrays (or Countable or Traversable objects) is the same.
param string$needleparam string$haystackparam string$messagereturn void
param string$needleparam string$haystackparam string$messagereturn void
param non-empty-string$suffixparam string$stringparam string$messagereturn void
Asserts that a string ends not with a given suffix.
param non-empty-string$suffixparam string$stringparam string$messagereturn void
Asserts that a string ends with a given suffix.
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is equal to the contents of a file.
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is equal to the contents of a file (canonicalizing).
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is equal to the contents of a file (ignoring case).
param string$formatparam string$stringparam string$messagereturn void
Asserts that a string matches a given format string.
param string$formatFileparam string$stringparam string$messagereturn void
Asserts that a string matches a given format file.
param string$needleparam string$haystackparam string$messagereturn void
param string$needleparam string$haystackparam string$messagereturn void
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is not equal to the contents of a file.
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is not equal to the contents of a file (canonicalizing).
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is not equal to the contents of a file (ignoring case).
param string$formatparam string$stringparam string$messagereturn void
Asserts that a string does not match a given format string.
param string$formatFileparam string$stringparam string$messagereturn void
Asserts that a string does not match a given format string.
param non-empty-string$prefixparam string$stringparam string$messagereturn void
Asserts that a string starts not with a given prefix.
param non-empty-string$prefixparam string$stringparam string$messagereturn void
Asserts that a string starts with a given prefix.
param mixed$valueparam \PHPUnit\Framework\Constraint\Constraint$constraintparam string$messagereturn void
Evaluates a PHPUnit\Framework\Constraint matcher object.
param mixed$valueparam \PHPUnit\Framework\Constraint\Constraint$constraintparam string$messagereturn void
Evaluates a PHPUnit\Framework\Constraint matcher object.
phpstan-asserttrue $conditionparam mixed$conditionparam string$messagereturn void
Asserts that a condition is true.
param string$expectedFileparam string$actualFileparam string$messagereturn void
Asserts that two XML files are equal.
param string$expectedFileparam string$actualFileparam string$messagereturn void
Asserts that two XML files are not equal.
param string$expectedFileparam \DOMDocument|string$actualXmlparam string$messagereturn void
Asserts that two XML documents are equal.
param \DOMDocument|string$expectedXmlparam \DOMDocument|string$actualXmlparam string$messagereturn void
Asserts that two XML documents are equal.
param string$expectedFileparam \DOMDocument|string$actualXmlparam string$messagereturn void
Asserts that two XML documents are not equal.
param \DOMDocument|string$expectedXmlparam \DOMDocument|string$actualXmlparam string$messagereturn void
Asserts that two XML documents are not equal.
param \Throwable|string$throwableparam callable$callbackreturn void
Handles and checks throwables (Exceptions/Errors) called inside the callback function.
Either throwable class name or throwable instance should be provided.
{% highlight php %}
expectThrowable(MyThrowable::class, function() { $this->doSomethingBad(); }); $I->expectThrowable(new MyException(), function() { $this->doSomethingBad(); }); {% endhighlight %} If you want to check message or throwable code, you can pass them with throwable instance: {% highlight php %} expectThrowable(new MyError("Don't do bad things"), function() { $this->doSomethingBad(); }); {% endhighlight %} #### fail * `param string` $message * `return never` Fails a test with the given message. #### markTestIncomplete * `param string` $message * `return never` Mark the test as incomplete. #### markTestSkipped * `param string` $message * `return never` Mark the test as skipped.