| CARVIEW |
Guides
- Introduction
- Getting Started
- Acceptance Tests
- Functional Tests
- Unit Tests
- Debugging
- Modules And Helpers
- Reusing Test Code
- Advanced Usage
- BDD
- Customization
- Data
- API Testing
- Codecoverage
- Reporting
- Continuous Integration
- Parallel Execution
Testomatio - Test Management for Codeception
Search
Asserts
Installation
composer require --dev codeception/module-assertsDescription
Special module for using asserts in your tests.
Actions
assertArrayHasKey
param string|int$keyparam \ArrayAccess|array$arrayparam string$messagereturn void
Asserts that an array has a specified key.
assertArrayNotHasKey
param string|int$keyparam \ArrayAccess|array$arrayparam string$messagereturn void
Asserts that an array does not have a specified key.
assertClassHasAttribute
param string$attributeNameparam class-string$classNameparam string$messagereturn void
Asserts that a class has a specified attribute.
assertClassHasStaticAttribute
param string$attributeNameparam class-string$classNameparam string$messagereturn void
Asserts that a class has a specified static attribute.
assertClassNotHasAttribute
param string$attributeNameparam class-string$classNameparam string$messagereturn void
Asserts that a class does not have a specified attribute.
assertClassNotHasStaticAttribute
param string$attributeNameparam class-string$classNameparam string$messagereturn void
Asserts that a class does not have a specified static attribute.
assertContains
param mixed$needleparam iterable<mixed>$haystackparam string$messagereturn void
Asserts that a haystack contains a needle.
assertContainsEquals
param mixed$needleparam iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyArray
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyBool
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyCallable
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyClosedResource
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyFloat
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyInstancesOf
param class-string$classNameparam iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyInt
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyIterable
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyNull
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyNumeric
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyObject
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyResource
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyScalar
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsNotOnlyString
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnly
param string$typeparam iterable<mixed>$haystackparam ?bool$isNativeTypeparam string$messagereturn void
Asserts that a haystack contains only values of a given type.
assertContainsOnlyArray
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyBool
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyCallable
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyClosedResource
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyFloat
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyInstancesOf
param class-string$classNameparam iterable<mixed>$haystackparam string$messagereturn void
Asserts that a haystack contains only instances of a given class name.
assertContainsOnlyInt
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyIterable
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyNull
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyNumeric
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyObject
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyResource
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyScalar
param iterable<mixed>$haystackparam string$messagereturn void
assertContainsOnlyString
param iterable<mixed>$haystackparam string$messagereturn void
assertCount
param int$expectedCountparam \Countable|iterable<mixed>$haystackparam string$messagereturn void
Asserts the number of elements of an array, Countable or Traversable.
assertDirectoryDoesNotExist
param string$directoryparam string$messagereturn void
Asserts that a directory does not exist.
assertDirectoryExists
param string$directoryparam string$messagereturn void
Asserts that a directory exists.
assertDirectoryIsNotReadable
param string$directoryparam string$messagereturn void
Asserts that a directory exists and is not readable.
assertDirectoryIsNotWritable
param string$directoryparam string$messagereturn void
Asserts that a directory exists and is not writable.
assertDirectoryIsReadable
param string$directoryparam string$messagereturn void
Asserts that a directory exists and is readable.
assertDirectoryIsWritable
param string$directoryparam string$messagereturn void
Asserts that a directory exists and is writable.
assertDoesNotMatchRegularExpression
param string$patternparam string$stringparam string$messagereturn void
Asserts that a string does not match a given regular expression.
assertEmpty
phpstan-assertempty $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is empty.
assertEquals
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are equal.
assertEqualsCanonicalizing
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are equal (canonicalizing).
assertEqualsIgnoringCase
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are equal (ignoring case).
assertEqualsWithDelta
param mixed$expectedparam mixed$actualparam float$deltaparam string$messagereturn void
Asserts that two variables are equal (with delta).
assertFalse
phpstan-assertfalse $conditionparam mixed$conditionparam string$messagereturn void
Asserts that a condition is false.
assertFileDoesNotExist
param string$filenameparam string$messagereturn void
Asserts that a file does not exist.
assertFileEquals
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is equal to the contents of another file.
assertFileEqualsCanonicalizing
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is equal to the contents of another file (canonicalizing).
assertFileEqualsIgnoringCase
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).
assertFileExists
param string$filenameparam string$messagereturn void
Asserts that a file exists.
assertFileIsNotReadable
param string$fileparam string$messagereturn void
Asserts that a file exists and is not readable.
assertFileIsNotWritable
param string$fileparam string$messagereturn void
Asserts that a file exists and is not writable.
assertFileIsReadable
param string$fileparam string$messagereturn void
Asserts that a file exists and is readable.
assertFileIsWritable
param string$fileparam string$messagereturn void
Asserts that a file exists and is writable.
assertFileNotEquals
param string$expectedparam string$actualparam string$messagereturn void
Asserts that the contents of one file is not equal to the contents of another file.
assertFileNotEqualsCanonicalizing
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).
assertFileNotEqualsIgnoringCase
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).
assertFileNotExists
param string$filenameparam string$messagereturn void
Asserts that a file does not exist.
assertFinite
param mixed$actualparam string$messagereturn void
Asserts that a variable is finite.
assertGreaterOrEquals
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is greater than or equal to another value.
assertGreaterThan
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is greater than another value.
assertGreaterThanOrEqual
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is greater than or equal to another value.
assertInfinite
param mixed$actualparam string$messagereturn void
Asserts that a variable is infinite.
assertInstanceOf
templateExpectedType of objectphpstan-assert=ExpectedType $actualparam class-string<ExpectedType>$expectedparam mixed$actualparam string$messagereturn void
Asserts that a variable is of a given type.
assertIsArray
phpstan-assertarray$actual param mixed$actualparam string$messagereturn void
Asserts that a variable is of type array.
assertIsBool
phpstan-assertbool $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type bool.
assertIsCallable
phpstan-assertcallable $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type callable.
assertIsClosedResource
phpstan-assertresource $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type resource and is closed.
assertIsEmpty
param mixed$actualparam string$messagereturn void
Asserts that a variable is empty.
assertIsFloat
phpstan-assertfloat $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type float.
assertIsInt
phpstan-assertint $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type int.
assertIsIterable
phpstan-assertiterable$actual param mixed$actualparam string$messagereturn void
Asserts that a variable is of type iterable.
assertIsNotArray
phpstan-assert!array$actual param mixed$actualparam string$messagereturn void
Asserts that a variable is not of type array.
assertIsNotBool
phpstan-assert!bool $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type bool.
assertIsNotCallable
phpstan-assert!callable $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type callable.
assertIsNotClosedResource
phpstan-assert!resource $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type resource.
assertIsNotFloat
phpstan-assert!float $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type float.
assertIsNotInt
phpstan-assert!int $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type int.
assertIsNotIterable
phpstan-assert!iterable$actual param mixed$actualparam string$messagereturn void
Asserts that a variable is not of type iterable.
assertIsNotNumeric
phpstan-assert!numeric $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type numeric.
assertIsNotObject
phpstan-assert!object $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type object.
assertIsNotReadable
param string$filenameparam string$messagereturn void
Asserts that a file/dir exists and is not readable.
assertIsNotResource
phpstan-assert!resource $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type resource.
assertIsNotScalar
psalm-assert!scalar $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type scalar.
assertIsNotString
phpstan-assert!string $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not of type string.
assertIsNotWritable
param string$filenameparam string$messagereturn void
Asserts that a file/dir exists and is not writable.
assertIsNumeric
phpstan-assertnumeric $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type numeric.
assertIsObject
phpstan-assertobject $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type object.
assertIsReadable
param string$filenameparam string$messagereturn void
Asserts that a file/dir is readable.
assertIsResource
phpstan-assertresource $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type resource.
assertIsScalar
phpstan-assertscalar $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type scalar.
assertIsString
phpstan-assertstring $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is of type string.
assertIsWritable
param string$filenameparam string$messagereturn void
Asserts that a file/dir exists and is writable.
assertJson
param string$actualJsonparam string$messagereturn void
Asserts that a string is a valid JSON string.
assertJsonFileEqualsJsonFile
param string$expectedFileparam string$actualFileparam string$messagereturn void
Asserts that two JSON files are equal.
assertJsonFileNotEqualsJsonFile
param string$expectedFileparam string$actualFileparam string$messagereturn void
Asserts that two JSON files are not equal.
assertJsonStringEqualsJsonFile
param string$expectedFileparam string$actualJsonparam string$messagereturn void
Asserts that the generated JSON encoded object and the content of the given file are equal.
assertJsonStringEqualsJsonString
param string$expectedJsonparam string$actualJsonparam string$messagereturn void
Asserts that two given JSON encoded objects or arrays are equal.
assertJsonStringNotEqualsJsonFile
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.
assertJsonStringNotEqualsJsonString
param string$expectedJsonparam string$actualJsonparam string$messagereturn void
Asserts that two given JSON encoded objects or arrays are not equal.
assertLessOrEquals
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is smaller than or equal to another value.
assertLessThan
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is smaller than another value.
assertLessThanOrEqual
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that a value is smaller than or equal to another value.
assertMatchesRegularExpression
param string$patternparam string$stringparam string$messagereturn void
Asserts that a string matches a given regular expression.
assertNan
param mixed$actualparam string$messagereturn void
Asserts that a variable is nan.
assertNotContains
param mixed$needleparam iterable<mixed>$haystackparam string$messagereturn void
Asserts that a haystack does not contain a needle.
assertNotContainsEquals
param mixed$needleparam iterable<mixed>$haystackparam string$messagereturn void
assertNotContainsOnly
param string$typeparam iterable<mixed>$haystackparam ?bool$isNativeTypeparam string$messagereturn void
Asserts that a haystack does not contain only values of a given type.
assertNotCount
param int$expectedCountparam \Countable|iterable<mixed>$haystackparam string$messagereturn void
Asserts the number of elements of an array, Countable or Traversable.
assertNotEmpty
phpstan-assert!empty $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not empty.
assertNotEquals
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are not equal.
assertNotEqualsCanonicalizing
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are not equal (canonicalizing).
assertNotEqualsIgnoringCase
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables are not equal (ignoring case).
assertNotEqualsWithDelta
param mixed$expectedparam mixed$actualparam float$deltaparam string$messagereturn void
Asserts that two variables are not equal (with delta).
assertNotFalse
phpstan-assert!false $conditionparam mixed$conditionparam string$messagereturn void
Asserts that a condition is not false.
assertNotInstanceOf
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.
assertNotNull
phpstan-assert!null $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is not null.
assertNotRegExp
param string$patternparam string$stringparam string$messagereturn void
Asserts that a string does not match a given regular expression.
assertNotSame
param mixed$expectedparam mixed$actualparam string$messagereturn void
Asserts that two variables do not have the same type and value.
assertNotSameSize
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.
assertNotTrue
phpstan-assert!true $conditionparam mixed$conditionparam string$messagereturn void
Asserts that a condition is not true.
assertNull
phpstan-assertnull $actualparam mixed$actualparam string$messagereturn void
Asserts that a variable is null.
assertObjectHasAttribute
param string$attributeNameparam object$objectparam string$messagereturn void
Asserts that an object has a specified attribute.
assertObjectNotHasAttribute
param string$attributeNameparam object$objectparam string$messagereturn void
Asserts that an object does not have a specified attribute.
assertRegExp
param string$patternparam string$stringparam string$messagereturn void
Asserts that a string matches a given regular expression.
assertSame
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.
assertSameSize
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.
assertStringContainsString
param string$needleparam string$haystackparam string$messagereturn void
assertStringContainsStringIgnoringCase
param string$needleparam string$haystackparam string$messagereturn void
assertStringEndsNotWith
param non-empty-string$suffixparam string$stringparam string$messagereturn void
Asserts that a string ends not with a given suffix.
assertStringEndsWith
param non-empty-string$suffixparam string$stringparam string$messagereturn void
Asserts that a string ends with a given suffix.
assertStringEqualsFile
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is equal to the contents of a file.
assertStringEqualsFileCanonicalizing
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is equal to the contents of a file (canonicalizing).
assertStringEqualsFileIgnoringCase
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).
assertStringMatchesFormat
param string$formatparam string$stringparam string$messagereturn void
Asserts that a string matches a given format string.
assertStringMatchesFormatFile
param string$formatFileparam string$stringparam string$messagereturn void
Asserts that a string matches a given format file.
assertStringNotContainsString
param string$needleparam string$haystackparam string$messagereturn void
assertStringNotContainsStringIgnoringCase
param string$needleparam string$haystackparam string$messagereturn void
assertStringNotEqualsFile
param string$expectedFileparam string$actualStringparam string$messagereturn void
Asserts that the contents of a string is not equal to the contents of a file.
assertStringNotEqualsFileCanonicalizing
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).
assertStringNotEqualsFileIgnoringCase
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).
assertStringNotMatchesFormat
param string$formatparam string$stringparam string$messagereturn void
Asserts that a string does not match a given format string.
assertStringNotMatchesFormatFile
param string$formatFileparam string$stringparam string$messagereturn void
Asserts that a string does not match a given format string.
assertStringStartsNotWith
param non-empty-string$prefixparam string$stringparam string$messagereturn void
Asserts that a string starts not with a given prefix.
assertStringStartsWith
param non-empty-string$prefixparam string$stringparam string$messagereturn void
Asserts that a string starts with a given prefix.
assertThat
param mixed$valueparam \PHPUnit\Framework\Constraint\Constraint$constraintparam string$messagereturn void
Evaluates a PHPUnit\Framework\Constraint matcher object.
assertThatItsNot
param mixed$valueparam \PHPUnit\Framework\Constraint\Constraint$constraintparam string$messagereturn void
Evaluates a PHPUnit\Framework\Constraint matcher object.
assertTrue
phpstan-asserttrue $conditionparam mixed$conditionparam string$messagereturn void
Asserts that a condition is true.
assertXmlFileEqualsXmlFile
param string$expectedFileparam string$actualFileparam string$messagereturn void
Asserts that two XML files are equal.
assertXmlFileNotEqualsXmlFile
param string$expectedFileparam string$actualFileparam string$messagereturn void
Asserts that two XML files are not equal.
assertXmlStringEqualsXmlFile
param string$expectedFileparam \DOMDocument|string$actualXmlparam string$messagereturn void
Asserts that two XML documents are equal.
assertXmlStringEqualsXmlString
param \DOMDocument|string$expectedXmlparam \DOMDocument|string$actualXmlparam string$messagereturn void
Asserts that two XML documents are equal.
assertXmlStringNotEqualsXmlFile
param string$expectedFileparam \DOMDocument|string$actualXmlparam string$messagereturn void
Asserts that two XML documents are not equal.
assertXmlStringNotEqualsXmlString
param \DOMDocument|string$expectedXmlparam \DOMDocument|string$actualXmlparam string$messagereturn void
Asserts that two XML documents are not equal.
expectThrowable
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.
<?php
$I->expectThrowable(MyThrowable::class, function() {
$this->doSomethingBad();
});
$I->expectThrowable(new MyException(), function() {
$this->doSomethingBad();
});If you want to check message or throwable code, you can pass them with throwable instance:
<?php
// will check that throwable MyError is thrown with "Don't do bad things" message
$I->expectThrowable(new MyError("Don't do bad things"), function() {
$this->doSomethingBad();
});fail
param string$messagereturn never
Fails a test with the given message.
markTestIncomplete
param string$messagereturn never
Mark the test as incomplete.
markTestSkipped
param string$messagereturn never
Mark the test as skipped.
Codeception is a BDD-styled PHP testing framework, brought to you by Codeception Team. OpenSource MIT Licensed.

