| 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.
param$keyparam$actualparam$description
param$keyparam$actualparam$description
Checks that haystack contains needle
param$needleparam$haystackparam string$message
param$expectedCountparam$actualparam$description
Checks that variable is empty.
param$actualparam string$message
Checks that two variables are equal.
param$expectedparam$actualparam string$messageparam float$delta
not documented
not documented
not documented
Checks that condition is negative.
param$conditionparam string$message
Checks if file exists
param string$filenameparam string$message
Checks if file doesn't exist
param string$filenameparam string$message
param$expectedparam$actualparam$description
Checks that actual is greater than expected
param$expectedparam$actualparam string$message
Checks that actual is greater or equal than expected
param$expectedparam$actualparam string$message
param$classparam$actualparam$description
param$typeparam$actualparam$description
not documented
not documented
not documented
param$actualparam$description
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
not documented
param$expectedparam$actualparam$description
Checks that actual is less than expected
param$expectedparam$actualparam string$message
Checks that actual is less or equal than expected
param$expectedparam$actualparam string$message
Checks that haystack doesn't contain needle.
param$needleparam$haystackparam string$message
Checks that variable is not empty.
param$actualparam string$message
Checks that two variables are not equal
param$expectedparam$actualparam string$messageparam float$delta
not documented
not documented
not documented
Checks that the condition is NOT false (everything but false)
param$conditionparam string$message
param$classparam$actualparam$description
Checks that variable is not NULL
param$actualparam string$message
Checks that string not match with pattern
param string$patternparam string$stringparam string$message
Checks that two variables are not same
param$expectedparam$actualparam string$message
Checks that the condition is NOT true (everything but true)
param$conditionparam string$message
Checks that variable is NULL
param$actualparam string$message
Checks that string match with pattern
param string$patternparam string$stringparam string$message
Checks that two variables are same
param$expectedparam$actualparam string$message
not documented
not documented
Available since1.1.0 of module-asserts
Available since1.1.0 of module-asserts
not documented
not documented
Checks that a string doesn't start with the given prefix.
param string$prefixparam string$stringparam string$message
Checks that a string starts with the given prefix.
param string$prefixparam string$stringparam string$message
Checks that condition is positive.
param$conditionparam string$message
Handles and checks exception called inside callback function. Either exception class name or exception instance should be provided.
{% highlight php %}
expectException(MyException::class, function() { $this->doSomethingBad(); }); $I->expectException(new MyException(), function() { $this->doSomethingBad(); }); {% endhighlight %} If you want to check message or exception code, you can pass them with exception instance: {% highlight php %} expectException(new MyException("Don't do bad things"), function() { $this->doSomethingBad(); }); {% endhighlight %} @deprecated Use expectThrowable() instead * `param` $exception string or \Exception * `param` $callback #### expectThrowable 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 or \Throwable * `param` $callback #### fail Fails the test with message. * `param` $message