Codeception\Util\Shared\Asserts
Basic class for Modules and Helpers. You must extend from it while implementing own helpers.
Public methods of this class start with _
prefix in order to ignore them in actor classes. Module contains HOOKS which allow to handle test execution routine.
public static $includeInheritedActions
By setting it to false module wan’t inherit methods of parent class.
type bool
public static $onlyActions
Allows to explicitly set what methods have this class.
type array
public static $excludeActions
Allows to explicitly exclude actions from module.
type array
public static $aliases
Allows to rename actions
type array
public __construct($moduleContainer, $config = null)
Module constructor.
Requires module container (to provide access between modules of suite) and config.
param ModuleContainer
$moduleContainerparam array|null
$configpublic _after($test)
HOOK executed after test
param TestInterface
$testpublic _afterStep($step)
HOOK executed after step
param Step
$steppublic _afterSuite()
HOOK executed after suite
public _before($test)
HOOK executed before test
param TestInterface
$testpublic _beforeStep($step)
HOOK executed before step
param Step
$steppublic _beforeSuite($settings = null)
HOOK executed before suite
param array
$settingspublic _failed($test, $fail)
HOOK executed when test fails but before _after
param TestInterface
$testparam \Exception
$failpublic _getConfig($key = null)
Get config values or specific config item.
param mixed
$keyreturn
mixed the config item’s value or null if it doesn’t existpublic _getName()
Returns a module name for a Module, a class name for Helper
return
stringpublic _hasRequiredFields()
Checks if a module has required fields
return
boolpublic _initialize()
HOOK triggered after module is created and configuration is loaded
public _reconfigure($config)
Allows to redefine config for a specific test. Config is restored at the end of a test.
<?php // cleanup DB only for specific group of tests public function _before(Test $test) { if (in_array('cleanup', $test->getMetadata()->getGroups()) { $this->getModule('Db')->_reconfigure(['cleanup' => true]); } }
param
$configthrows
Exception\ModuleConfigExceptionthrows
ModuleExceptionpublic _resetConfig()
Reverts config changed by _reconfigure
public _setConfig($config)
Allows to define initial module config. Can be used in _beforeSuite
hook of Helpers or Extensions
<?php public function _beforeSuite($settings = []) { $this->getModule('otherModule')->_setConfig($this->myOtherConfig); }
param
$configthrows
Exception\ModuleConfigExceptionthrows
ModuleExceptionprotected assert($arguments, $not = null)
param
$argumentsparam bool
$notprotected assertArrayHasKey($key, $array, $message = null)
Asserts that an array has a specified key.
param int|string
$keyparam array|ArrayAccess
$arrayparam string
$messageprotected assertArrayNotHasKey($key, $array, $message = null)
Asserts that an array does not have a specified key.
param int|string
$keyparam array|ArrayAccess
$arrayparam string
$messageprotected assertClassHasAttribute($attributeName, $className, $message = null)
Asserts that a class has a specified attribute.
param string
$attributeNameparam string
$classNameparam string
$messageprotected assertClassHasStaticAttribute($attributeName, $className, $message = null)
Asserts that a class has a specified static attribute.
param string
$attributeNameparam string
$classNameparam string
$messageprotected assertClassNotHasAttribute($attributeName, $className, $message = null)
Asserts that a class does not have a specified attribute.
param string
$attributeNameparam string
$classNameparam string
$messageprotected assertClassNotHasStaticAttribute($attributeName, $className, $message = null)
Asserts that a class does not have a specified static attribute.
param string
$attributeNameparam string
$classNameparam string
$messageprotected assertContains($needle, $haystack, $message = null)
Asserts that a haystack contains a needle.
param
$needleparam
$haystackparam string
$messageprotected assertContainsEquals($needle, $haystack, $message = null)
param
$needleparam
$haystackparam string
$messageprotected assertContainsOnly($type, $haystack, $isNativeType = null, $message = null)
Asserts that a haystack contains only values of a given type.
param string
$typeparam
$haystackparam bool|null
$isNativeTypeparam string
$messageprotected assertContainsOnlyInstancesOf($className, $haystack, $message = null)
Asserts that a haystack contains only instances of a given class name.
param string
$classNameparam
$haystackparam string
$messageprotected assertCount($expectedCount, $haystack, $message = null)
Asserts the number of elements of an array, Countable or Traversable.
param int
$expectedCountparam Countable|iterable
$haystackparam string
$messageprotected assertDirectoryDoesNotExist($directory, $message = null)
Asserts that a directory does not exist.
param string
$directoryparam string
$messageprotected assertDirectoryExists($directory, $message = null)
Asserts that a directory exists.
param string
$directoryparam string
$messageprotected assertDirectoryIsNotReadable($directory, $message = null)
Asserts that a directory exists and is not readable.
param string
$directoryparam string
$messageprotected assertDirectoryIsNotWritable($directory, $message = null)
Asserts that a directory exists and is not writable.
param string
$directoryparam string
$messageprotected assertDirectoryIsReadable($directory, $message = null)
Asserts that a directory exists and is readable.
param string
$directoryparam string
$messageprotected assertDirectoryIsWritable($directory, $message = null)
Asserts that a directory exists and is writable.
param string
$directoryparam string
$messageprotected assertDoesNotMatchRegularExpression($pattern, $string, $message = null)
Asserts that a string does not match a given regular expression.
param string
$patternparam string
$stringparam string
$messageprotected assertEmpty($actual, $message = null)
Asserts that a variable is empty.
param
$actualparam string
$messageprotected assertEquals($expected, $actual, $message = null)
Asserts that two variables are equal.
param
$expectedparam
$actualparam string
$messageprotected assertEqualsCanonicalizing($expected, $actual, $message = null)
Asserts that two variables are equal (canonicalizing).
param
$expectedparam
$actualparam string
$messageprotected assertEqualsIgnoringCase($expected, $actual, $message = null)
Asserts that two variables are equal (ignoring case).
param
$expectedparam
$actualparam string
$messageprotected assertEqualsWithDelta($expected, $actual, $delta, $message = null)
Asserts that two variables are equal (with delta).
param
$expectedparam
$actualparam float
$deltaparam string
$messageprotected assertFalse($condition, $message = null)
Asserts that a condition is false.
param
$conditionparam string
$messageprotected assertFileDoesNotExist($filename, $message = null)
Asserts that a file does not exist.
param string
$filenameparam string
$messageprotected assertFileEquals($expected, $actual, $message = null)
Asserts that the contents of one file is equal to the contents of another file.
param string
$expectedparam string
$actualparam string
$messageprotected assertFileEqualsCanonicalizing($expected, $actual, $message = null)
Asserts that the contents of one file is equal to the contents of another file (canonicalizing).
param
$expectedparam
$actualparam string
$messageprotected assertFileEqualsIgnoringCase($expected, $actual, $message = null)
Asserts that the contents of one file is equal to the contents of another file (ignoring case).
param
$expectedparam
$actualparam string
$messageprotected assertFileExists($filename, $message = null)
Asserts that a file exists.
param string
$filenameparam string
$messageprotected assertFileIsNotReadable($file, $message = null)
Asserts that a file exists and is not readable.
param string
$fileparam string
$messageprotected assertFileIsNotWritable($file, $message = null)
Asserts that a file exists and is not writable.
param string
$fileparam string
$messageprotected assertFileIsReadable($file, $message = null)
Asserts that a file exists and is readable.
param string
$fileparam string
$messageprotected assertFileIsWritable($file, $message = null)
Asserts that a file exists and is writable.
param string
$fileparam string
$messageprotected assertFileNotEquals($expected, $actual, $message = null)
Asserts that the contents of one file is not equal to the contents of another file.
param
$expectedparam
$actualparam string
$messageprotected assertFileNotEqualsCanonicalizing($expected, $actual, $message = null)
Asserts that the contents of one file is not equal to the contents of another file (canonicalizing).
param
$expectedparam
$actualparam string
$messageprotected assertFileNotEqualsIgnoringCase($expected, $actual, $message = null)
Asserts that the contents of one file is not equal to the contents of another file (ignoring case).
param
$expectedparam
$actualparam string
$messageprotected assertFileNotExists($filename, $message = null)
Asserts that a file does not exist.
param string
$filenameparam string
$messageprotected assertFinite($actual, $message = null)
Asserts that a variable is finite.
param
$actualparam string
$messageprotected assertGreaterOrEquals($expected, $actual, $message = null)
Asserts that a value is greater than or equal to another value.
param
$expectedparam
$actualparam string
$messageprotected assertGreaterThan($expected, $actual, $message = null)
Asserts that a value is greater than another value.
param
$expectedparam
$actualparam string
$messageprotected assertGreaterThanOrEqual($expected, $actual, $message = null)
Asserts that a value is greater than or equal to another value.
param
$expectedparam
$actualparam string
$messageprotected assertInfinite($actual, $message = null)
Asserts that a variable is infinite.
param
$actualparam string
$messageprotected assertInstanceOf($expected, $actual, $message = null)
Asserts that a variable is of a given type.
param
$expectedparam
$actualparam string
$messageprotected assertIsArray($actual, $message = null)
Asserts that a variable is of type array.
param
$actualparam string
$messageprotected assertIsBool($actual, $message = null)
Asserts that a variable is of type bool.
param
$actualparam string
$messageprotected assertIsCallable($actual, $message = null)
Asserts that a variable is of type callable.
param
$actualparam string
$messageprotected assertIsClosedResource($actual, $message = null)
Asserts that a variable is of type resource and is closed.
param
$actualparam string
$messageprotected assertIsEmpty($actual, $message = null)
Asserts that a variable is empty.
param
$actualparam string
$messageprotected assertIsFloat($actual, $message = null)
Asserts that a variable is of type float.
param
$actualparam string
$messageprotected assertIsInt($actual, $message = null)
Asserts that a variable is of type int.
param
$actualparam string
$messageprotected assertIsIterable($actual, $message = null)
Asserts that a variable is of type iterable.
param
$actualparam string
$messageprotected assertIsNotArray($actual, $message = null)
Asserts that a variable is not of type array.
param
$actualparam string
$messageprotected assertIsNotBool($actual, $message = null)
Asserts that a variable is not of type bool.
param
$actualparam string
$messageprotected assertIsNotCallable($actual, $message = null)
Asserts that a variable is not of type callable.
param
$actualparam string
$messageprotected assertIsNotClosedResource($actual, $message = null)
Asserts that a variable is not of type resource.
param
$actualparam string
$messageprotected assertIsNotFloat($actual, $message = null)
Asserts that a variable is not of type float.
param
$actualparam string
$messageprotected assertIsNotInt($actual, $message = null)
Asserts that a variable is not of type int.
param
$actualparam string
$messageprotected assertIsNotIterable($actual, $message = null)
Asserts that a variable is not of type iterable.
param
$actualparam string
$messageprotected assertIsNotNumeric($actual, $message = null)
Asserts that a variable is not of type numeric.
param
$actualparam string
$messageprotected assertIsNotObject($actual, $message = null)
Asserts that a variable is not of type object.
param
$actualparam string
$messageprotected assertIsNotReadable($filename, $message = null)
Asserts that a file/dir exists and is not readable.
param string
$filenameparam string
$messageprotected assertIsNotResource($actual, $message = null)
Asserts that a variable is not of type resource.
param
$actualparam string
$messageprotected assertIsNotScalar($actual, $message = null)
Asserts that a variable is not of type scalar.
param
$actualparam string
$messageprotected assertIsNotString($actual, $message = null)
Asserts that a variable is not of type string.
param
$actualparam string
$messageprotected assertIsNotWritable($filename, $message = null)
Asserts that a file/dir exists and is not writable.
param
$filenameparam string
$messageprotected assertIsNumeric($actual, $message = null)
Asserts that a variable is of type numeric.
param
$actualparam string
$messageprotected assertIsObject($actual, $message = null)
Asserts that a variable is of type object.
param
$actualparam string
$messageprotected assertIsReadable($filename, $message = null)
Asserts that a file/dir is readable.
param
$filenameparam string
$messageprotected assertIsResource($actual, $message = null)
Asserts that a variable is of type resource.
param
$actualparam string
$messageprotected assertIsScalar($actual, $message = null)
Asserts that a variable is of type scalar.
param
$actualparam string
$messageprotected assertIsString($actual, $message = null)
Asserts that a variable is of type string.
param
$actualparam string
$messageprotected assertIsWritable($filename, $message = null)
Asserts that a file/dir exists and is writable.
param
$filenameparam string
$messageprotected assertJson($actualJson, $message = null)
Asserts that a string is a valid JSON string.
param string
$actualJsonparam string
$messageprotected assertJsonFileEqualsJsonFile($expectedFile, $actualFile, $message = null)
Asserts that two JSON files are equal.
param string
$expectedFileparam string
$actualFileparam string
$messageprotected assertJsonFileNotEqualsJsonFile($expectedFile, $actualFile, $message = null)
Asserts that two JSON files are not equal.
param string
$expectedFileparam string
$actualFileparam string
$messageprotected assertJsonStringEqualsJsonFile($expectedFile, $actualJson, $message = null)
Asserts that the generated JSON encoded object and the content of the given file are equal.
param string
$expectedFileparam string
$actualJsonparam string
$messageprotected assertJsonStringEqualsJsonString($expectedJson, $actualJson, $message = null)
Asserts that two given JSON encoded objects or arrays are equal.
param string
$expectedJsonparam string
$actualJsonparam string
$messageprotected assertJsonStringNotEqualsJsonFile($expectedFile, $actualJson, $message = null)
Asserts that the generated JSON encoded object and the content of the given file are not equal.
param string
$expectedFileparam string
$actualJsonparam string
$messageprotected assertJsonStringNotEqualsJsonString($expectedJson, $actualJson, $message = null)
Asserts that two given JSON encoded objects or arrays are not equal.
param string
$expectedJsonparam string
$actualJsonparam string
$messageprotected assertLessOrEquals($expected, $actual, $message = null)
Asserts that a value is smaller than or equal to another value.
param
$expectedparam
$actualparam string
$messageprotected assertLessThan($expected, $actual, $message = null)
Asserts that a value is smaller than another value.
param
$expectedparam
$actualparam string
$messageprotected assertLessThanOrEqual($expected, $actual, $message = null)
Asserts that a value is smaller than or equal to another value.
param
$expectedparam
$actualparam string
$messageprotected assertMatchesRegularExpression($pattern, $string, $message = null)
Asserts that a string matches a given regular expression.
param string
$patternparam string
$stringparam string
$messageprotected assertNan($actual, $message = null)
Asserts that a variable is nan.
param
$actualparam string
$messageprotected assertNot($arguments)
protected assertNotContains($needle, $haystack, $message = null)
Asserts that a haystack does not contain a needle.
param
$needleparam
$haystackparam string
$messageprotected assertNotContainsEquals($needle, $haystack, $message = null)
protected assertNotContainsOnly($type, $haystack, $isNativeType = null, $message = null)
Asserts that a haystack does not contain only values of a given type.
param string
$typeparam
$haystackparam bool|null
$isNativeTypeparam string
$messageprotected assertNotCount($expectedCount, $haystack, $message = null)
Asserts the number of elements of an array, Countable or Traversable.
param int
$expectedCountparam Countable|iterable
$haystackparam string
$messageprotected assertNotEmpty($actual, $message = null)
Asserts that a variable is not empty.
param
$actualparam string
$messageprotected assertNotEquals($expected, $actual, $message = null)
Asserts that two variables are not equal.
param
$expectedparam
$actualparam string
$messageprotected assertNotEqualsCanonicalizing($expected, $actual, $message = null)
Asserts that two variables are not equal (canonicalizing).
param
$expectedparam
$actualparam string
$messageprotected assertNotEqualsIgnoringCase($expected, $actual, $message = null)
Asserts that two variables are not equal (ignoring case).
param
$expectedparam
$actualparam string
$messageprotected assertNotEqualsWithDelta($expected, $actual, $delta, $message = null)
Asserts that two variables are not equal (with delta).
param
$expectedparam
$actualparam float
$deltaparam string
$messageprotected assertNotFalse($condition, $message = null)
Asserts that a condition is not false.
param
$conditionparam string
$messageprotected assertNotInstanceOf($expected, $actual, $message = null)
Asserts that a variable is not of a given type.
param
$expectedparam
$actualparam string
$messageprotected assertNotNull($actual, $message = null)
Asserts that a variable is not null.
param
$actualparam string
$messageprotected assertNotRegExp($pattern, $string, $message = null)
Asserts that a string does not match a given regular expression.
param string
$patternparam string
$stringparam string
$messageprotected assertNotSame($expected, $actual, $message = null)
Asserts that two variables do not have the same type and value.
param
$expectedparam
$actualparam string
$messageprotected assertNotSameSize($expected, $actual, $message = null)
Assert that the size of two arrays (or Countable
or Traversable
objects) is not the same.
param Countable|iterable
$expectedparam Countable|iterable
$actualparam string
$messageprotected assertNotTrue($condition, $message = null)
Asserts that a condition is not true.
param
$conditionparam string
$messageprotected assertNull($actual, $message = null)
Asserts that a variable is null.
param
$actualparam string
$messageprotected assertObjectHasAttribute($attributeName, $object, $message = null)
Asserts that an object has a specified attribute.
param string
$attributeNameparam object
$objectparam string
$messageprotected assertObjectNotHasAttribute($attributeName, $object, $message = null)
Asserts that an object does not have a specified attribute.
param string
$attributeNameparam object
$objectparam string
$messageprotected assertRegExp($pattern, $string, $message = null)
Asserts that a string matches a given regular expression.
param string
$patternparam string
$stringparam string
$messageprotected assertSame($expected, $actual, $message = null)
Asserts that two variables have the same type and value.
param
$expectedparam
$actualparam string
$messageprotected assertSameSize($expected, $actual, $message = null)
Assert that the size of two arrays (or Countable
or Traversable
objects) is the same.
param Countable|iterable
$expectedparam Countable|iterable
$actualparam string
$messageprotected assertStringContainsString($needle, $haystack, $message = null)
param string
$needleparam string
$haystackparam string
$messageprotected assertStringContainsStringIgnoringCase($needle, $haystack, $message = null)
protected assertStringEndsNotWith($suffix, $string, $message = null)
Asserts that a string ends not with a given suffix.
param string
$suffixparam string
$stringparam string
$messageprotected assertStringEndsWith($suffix, $string, $message = null)
Asserts that a string ends with a given suffix.
param string
$suffixparam string
$stringparam string
$messageprotected assertStringEqualsFile($expectedFile, $actualString, $message = null)
Asserts that the contents of a string is equal to the contents of a file.
param string
$expectedFileparam string
$actualStringparam string
$messageprotected assertStringEqualsFileCanonicalizing($expectedFile, $actualString, $message = null)
Asserts that the contents of a string is equal to the contents of a file (canonicalizing).
param string
$expectedFileparam string
$actualStringparam string
$messageprotected assertStringEqualsFileIgnoringCase($expectedFile, $actualString, $message = null)
Asserts that the contents of a string is equal to the contents of a file (ignoring case).
param string
$expectedFileparam string
$actualStringparam string
$messageprotected assertStringMatchesFormat($format, $string, $message = null)
Asserts that a string matches a given format string.
param string
$formatparam string
$stringparam string
$messageprotected assertStringMatchesFormatFile($formatFile, $string, $message = null)
Asserts that a string matches a given format file.
param string
$formatFileparam string
$stringparam string
$messageprotected assertStringNotContainsString($needle, $haystack, $message = null)
param string
$needleparam string
$haystackparam string
$messageprotected assertStringNotContainsStringIgnoringCase($needle, $haystack, $message = null)
param string
$needleparam string
$haystackparam string
$messageprotected assertStringNotEqualsFile($expectedFile, $actualString, $message = null)
Asserts that the contents of a string is not equal to the contents of a file.
param string
$expectedFileparam string
$actualStringparam string
$messageprotected assertStringNotEqualsFileCanonicalizing($expectedFile, $actualString, $message = null)
Asserts that the contents of a string is not equal to the contents of a file (canonicalizing).
param string
$expectedFileparam string
$actualStringparam string
$messageprotected assertStringNotEqualsFileIgnoringCase($expectedFile, $actualString, $message = null)
Asserts that the contents of a string is not equal to the contents of a file (ignoring case).
param string
$expectedFileparam string
$actualStringparam string
$messageprotected assertStringNotMatchesFormat($format, $string, $message = null)
Asserts that a string does not match a given format string.
param string
$formatparam string
$stringparam string
$messageprotected assertStringNotMatchesFormatFile($formatFile, $string, $message = null)
Asserts that a string does not match a given format string.
param string
$formatFileparam string
$stringparam string
$messageprotected assertStringStartsNotWith($prefix, $string, $message = null)
Asserts that a string starts not with a given prefix.
param string
$prefixparam string
$stringparam string
$messageprotected assertStringStartsWith($prefix, $string, $message = null)
Asserts that a string starts with a given prefix.
param string
$prefixparam string
$stringparam string
$messageprotected assertThat($value, $constraint, $message = null)
Evaluates a PHPUnit\Framework\Constraint matcher object.
param
$valueparam Constraint
$constraintparam string
$messageprotected assertThatItsNot($value, $constraint, $message = null)
Evaluates a PHPUnit\Framework\Constraint matcher object.
param
$valueparam Constraint
$constraintparam string
$messageprotected assertTrue($condition, $message = null)
Asserts that a condition is true.
param
$conditionparam string
$messageprotected assertXmlFileEqualsXmlFile($expectedFile, $actualFile, $message = null)
Asserts that two XML files are equal.
param string
$expectedFileparam string
$actualFileparam string
$messageprotected assertXmlFileNotEqualsXmlFile($expectedFile, $actualFile, $message = null)
Asserts that two XML files are not equal.
param string
$expectedFileparam string
$actualFileparam string
$messageprotected assertXmlStringEqualsXmlFile($expectedFile, $actualXml, $message = null)
Asserts that two XML documents are equal.
param string
$expectedFileparam DOMDocument|string
$actualXmlparam string
$messageprotected assertXmlStringEqualsXmlString($expectedXml, $actualXml, $message = null)
Asserts that two XML documents are equal.
param DOMDocument|string
$expectedXmlparam DOMDocument|string
$actualXmlparam string
$messageprotected assertXmlStringNotEqualsXmlFile($expectedFile, $actualXml, $message = null)
Asserts that two XML documents are not equal.
param string
$expectedFileparam DOMDocument|string
$actualXmlparam string
$messageprotected assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, $message = null)
Asserts that two XML documents are not equal.
param DOMDocument|string
$expectedXmlparam DOMDocument|string
$actualXmlparam string
$messageprotected debug($message)
Print debug message to the screen.
param
$messageprotected debugSection($title, $message)
Print debug message with a title
param
$titleparam
$messageprotected fail($message = null)
Fails a test with the given message.
param string
$messageprotected getModule($name)
Get another module by its name:
<?php $this->getModule('WebDriver')->_findElements('.items');
param
$namereturn
Modulethrows
ModuleExceptionprotected getModules()
Get all enabled modules
return
arrayprotected hasModule($name)
Checks that module is enabled.
param
$namereturn
boolprotected markTestIncomplete($message = null)
Mark the test as incomplete.
param string
$messageprotected markTestSkipped($message = null)
Mark the test as skipped.
param string
$messageprotected onReconfigure()
HOOK to be executed when config changes with _reconfigure
.
protected scalarizeArray($array)
protected shortenMessage($message, $chars = null)
Short text message to an amount of chars
param
$messageparam
$charsreturn
stringprotected validateConfig()
Validates current config for required fields and required packages.
throws
Exception\ModuleConfigExceptionthrows
ModuleException
© 2011 Michael Bodnarchuk and contributors
Licensed under the MIT License.
https://codeception.com/docs/reference/Module