| layout | doc |
|---|---|
| title | Asserts - Codeception - Documentation |
If you use Codeception installed using composer, install this module with the following command:
{% highlight yaml %} composer require --dev codeception/module-asserts
{% endhighlight %}
Alternatively, you can enable Asserts module in suite configuration file and run
{% highlight yaml %} codecept init upgrade4
{% endhighlight %}
This module was bundled with Codeception 2 and 3, but since version 4 it is necessary to install it separately.
Some modules are bundled with PHAR files.
Warning. Using PHAR file and composer in the same project can cause unexpected errors.
Special module for using asserts in your tests.
Asserts that an array has a specified key.
param int|string$keyparam array|ArrayAccess$array
Asserts that an array does not have a specified key.
param int|string$keyparam array|ArrayAccess$array
Asserts that a class has a specified attribute.
Asserts that a class has a specified static attribute.
Asserts that a class does not have a specified attribute.
Asserts that a class does not have a specified static attribute.
Asserts that a haystack contains a needle.
param mixed$needle
param mixed$needle
Asserts that a haystack contains only values of a given type.
Asserts that a haystack contains only instances of a given class name.
Asserts the number of elements of an array, Countable or Traversable.
param Countable|iterable$haystack
Asserts that a directory does not exist.
Asserts that a directory exists.
Asserts that a directory exists and is not readable.
Asserts that a directory exists and is not writable.
Asserts that a directory exists and is readable.
Asserts that a directory exists and is writable.
Asserts that a string does not match a given regular expression.
Asserts that a variable is empty.
param mixed$actual
Asserts that two variables are equal.
param mixed$expectedparam mixed$actual
Asserts that two variables are equal (canonicalizing).
param mixed$expectedparam mixed$actual
Asserts that two variables are equal (ignoring case).
param mixed$expectedparam mixed$actual
Asserts that two variables are equal (with delta).
param mixed$expectedparam mixed$actual
Asserts that a condition is false.
param mixed$condition
Asserts that a file does not exist.
Asserts that the contents of one file is equal to the contents of another file.
Asserts that the contents of one file is equal to the contents of another file (canonicalizing).
Asserts that the contents of one file is equal to the contents of another file (ignoring case).
Asserts that a file exists.
Asserts that a file exists and is not readable.
Asserts that a file exists and is not writable.
Asserts that a file exists and is readable.
Asserts that a file exists and is writable.
Asserts that the contents of one file is not equal to the contents of another file.
Asserts that the contents of one file is not equal to the contents of another file (canonicalizing).
Asserts that the contents of one file is not equal to the contents of another file (ignoring case).
Asserts that a file does not exist.
Asserts that a variable is finite.
param mixed$actual
Asserts that a value is greater than or equal to another value.
param mixed$expectedparam mixed$actual
Asserts that a value is greater than another value.
param mixed$expectedparam mixed$actual
Asserts that a value is greater than or equal to another value.
param mixed$expectedparam mixed$actual
Asserts that a variable is infinite.
param mixed$actual
Asserts that a variable is of a given type.
param mixed$actual
Asserts that a variable is of type array.
param mixed$actual
Asserts that a variable is of type bool.
param mixed$actual
Asserts that a variable is of type callable.
param mixed$actual
Asserts that a variable is of type resource and is closed.
param mixed$actual
Asserts that a variable is empty.
param mixed$actual
Asserts that a variable is of type float.
param mixed$actual
Asserts that a variable is of type int.
param mixed$actual
Asserts that a variable is of type iterable.
param mixed$actual
Asserts that a variable is not of type array.
param mixed$actual
Asserts that a variable is not of type bool.
param mixed$actual
Asserts that a variable is not of type callable.
param mixed$actual
Asserts that a variable is not of type resource.
param mixed$actual
Asserts that a variable is not of type float.
param mixed$actual
Asserts that a variable is not of type int.
param mixed$actual
Asserts that a variable is not of type iterable.
param mixed$actual
Asserts that a variable is not of type numeric.
param mixed$actual
Asserts that a variable is not of type object.
param mixed$actual
Asserts that a file/dir exists and is not readable.
Asserts that a variable is not of type resource.
param mixed$actual
Asserts that a variable is not of type scalar.
param mixed$actual
Asserts that a variable is not of type string.
param mixed$actual
Asserts that a file/dir exists and is not writable.
Asserts that a variable is of type numeric.
param mixed$actual
Asserts that a variable is of type object.
param mixed$actual
Asserts that a file/dir is readable.
Asserts that a variable is of type resource.
param mixed$actual
Asserts that a variable is of type scalar.
param mixed$actual
Asserts that a variable is of type string.
param mixed$actual
Asserts that a file/dir exists and is writable.
Asserts that a string is a valid JSON string.
Asserts that two JSON files are equal.
Asserts that two JSON files are not equal.
Asserts that the generated JSON encoded object and the content of the given file are equal.
Asserts that two given JSON encoded objects or arrays are equal.
Asserts that the generated JSON encoded object and the content of the given file are not equal.
Asserts that two given JSON encoded objects or arrays are not equal.
Asserts that a value is smaller than or equal to another value.
param mixed$expectedparam mixed$actual
Asserts that a value is smaller than another value.
param mixed$expectedparam mixed$actual
Asserts that a value is smaller than or equal to another value.
param mixed$expectedparam mixed$actual
Asserts that a string matches a given regular expression.
Asserts that a variable is nan.
param mixed$actual
Asserts that a haystack does not contain a needle.
param mixed$needle
not documented
Asserts that a haystack does not contain only values of a given type.
Asserts the number of elements of an array, Countable or Traversable.
param Countable|iterable$haystack
Asserts that a variable is not empty.
param mixed$actual
Asserts that two variables are not equal.
param mixed$expectedparam mixed$actual
Asserts that two variables are not equal (canonicalizing).
param mixed$expectedparam mixed$actual
Asserts that two variables are not equal (ignoring case).
param mixed$expectedparam mixed$actual
Asserts that two variables are not equal (with delta).
param mixed$expectedparam mixed$actual
Asserts that a condition is not false.
param mixed$condition
Asserts that a variable is not of a given type.
param mixed$actual
Asserts that a variable is not null.
param mixed$actual
Asserts that a string does not match a given regular expression.
Asserts that two variables do not have the same type and value.
param mixed$expectedparam mixed$actual
Assert that the size of two arrays (or Countable or Traversable objects) is not the same.
param Countable|iterable$expectedparam Countable|iterable$actual
Asserts that a condition is not true.
param mixed$condition
Asserts that a variable is null.
param mixed$actual
Asserts that an object has a specified attribute.
Asserts that an object does not have a specified attribute.
Asserts that a string matches a given regular expression.
Asserts that two variables have the same type and value.
param mixed$expectedparam mixed$actual
Assert that the size of two arrays (or Countable or Traversable objects) is the same.
param Countable|iterable$expectedparam Countable|iterable$actual
not documented
not documented
Asserts that a string ends not with a given suffix.
Asserts that a string ends with a given suffix.
Asserts that the contents of a string is equal to the contents of a file.
Asserts that the contents of a string is equal to the contents of a file (canonicalizing).
Asserts that the contents of a string is equal to the contents of a file (ignoring case).
Asserts that a string matches a given format string.
Asserts that a string matches a given format file.
not documented
not documented
Asserts that the contents of a string is not equal to the contents of a file.
Asserts that the contents of a string is not equal to the contents of a file (canonicalizing).
Asserts that the contents of a string is not equal to the contents of a file (ignoring case).
Asserts that a string does not match a given format string.
Asserts that a string does not match a given format string.
Asserts that a string starts not with a given prefix.
Asserts that a string starts with a given prefix.
Evaluates a PHPUnit\Framework\Constraint matcher object.
param mixed$value
Evaluates a PHPUnit\Framework\Constraint matcher object.
param mixed$value
Asserts that a condition is true.
param mixed$condition
Asserts that two XML files are equal.
Asserts that two XML files are not equal.
Asserts that two XML documents are equal.
param DOMDocument|string$actualXml
Asserts that two XML documents are equal.
param DOMDocument|string$expectedXmlparam DOMDocument|string$actualXml
Asserts that two XML documents are not equal.
param DOMDocument|string$actualXml
Asserts that two XML documents are not equal.
param DOMDocument|string$expectedXmlparam DOMDocument|string$actualXml
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 %} * `param \Throwable|string` $throwable #### fail Fails a test with the given message. #### markTestIncomplete Mark the test as incomplete. #### markTestSkipped Mark the test as skipped.