Search

Codeception\Module

  • Uses 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.

$includeInheritedActions

public static $includeInheritedActions

By setting it to false module wan’t inherit methods of parent class.

$onlyActions

public static $onlyActions

Allows to explicitly set what methods have this class.

$excludeActions

public static $excludeActions

Allows to explicitly exclude actions from module.

$aliases

public static $aliases

Allows to rename actions

__construct()

public __construct($moduleContainer, array $config = null)

  • param \Codeception\Lib\ModuleContainer $moduleContainer
  • param ?array $config

Module constructor.

Requires module container (to provide access between modules of suite) and config.

See source

_after()

public _after($test)

  • param \Codeception\TestInterface $test

HOOK executed after test

See source

_afterStep()

public _afterStep($step)

  • param \Codeception\Step $step

HOOK executed after step

See source

_afterSuite()

public _afterSuite()

HOOK executed after suite

See source

_before()

public _before($test)

  • param \Codeception\TestInterface $test

HOOK executed before test

See source

_beforeStep()

public _beforeStep($step)

  • param \Codeception\Step $step

HOOK executed before step

See source

_beforeSuite()

public _beforeSuite(array $settings = array ( ))

  • param array $settings

HOOK executed before suite

See source

_failed()

public _failed($test, $fail)

  • param \Codeception\TestInterface $test
  • param \Exception $fail

HOOK executed when test fails but before _after

See source

_getConfig()

public _getConfig($key = null)

  • param string|null $key
  • return mixed the config item’s value or null if it doesn’t exist

Get config values or specific config item.

See source

_getName()

public _getName()

  • return string

Returns a module name for a Module, a class name for Helper

See source

_hasRequiredFields()

public _hasRequiredFields()

  • return bool

Checks if a module has required fields

See source

_initialize()

public _initialize()

HOOK triggered after module is created and configuration is loaded

See source

_reconfigure()

public _reconfigure(array $config)

  • param array $config
  • throws ModuleConfigException|ModuleException
  • return void

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]);
    }
}

See source

_resetConfig()

public _resetConfig()

  • return void

Reverts config changed by _reconfigure

See source

_setConfig()

public _setConfig(array $config)

  • param array $config
  • throws ModuleConfigException|ModuleException
  • return void

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);
}

See source

assert()

protected assert(array $arguments, $not = false)

  • param array $arguments
  • param bool $not
  • return void

See source

assertArrayHasKey()

protected assertArrayHasKey($key, $array, $message = β€˜β€™)

  • param string|int $key
  • param \ArrayAccess|array $array
  • param string $message
  • return void

Asserts that an array has a specified key.

See source

assertArrayNotHasKey()

protected assertArrayNotHasKey($key, $array, $message = β€˜β€™)

  • param string|int $key
  • param \ArrayAccess|array $array
  • param string $message
  • return void

Asserts that an array does not have a specified key.

See source

assertClassHasAttribute()

protected assertClassHasAttribute($attributeName, $className, $message = β€˜β€™)

  • param string $attributeName
  • param class-string $className
  • param string $message
  • return void

Asserts that a class has a specified attribute.

See source

assertClassHasStaticAttribute()

protected assertClassHasStaticAttribute($attributeName, $className, $message = β€˜β€™)

  • param string $attributeName
  • param class-string $className
  • param string $message
  • return void

Asserts that a class has a specified static attribute.

See source

assertClassNotHasAttribute()

protected assertClassNotHasAttribute($attributeName, $className, $message = β€˜β€™)

  • param string $attributeName
  • param class-string $className
  • param string $message
  • return void

Asserts that a class does not have a specified attribute.

See source

assertClassNotHasStaticAttribute()

protected assertClassNotHasStaticAttribute($attributeName, $className, $message = β€˜β€™)

  • param string $attributeName
  • param class-string $className
  • param string $message
  • return void

Asserts that a class does not have a specified static attribute.

See source

assertContains()

protected assertContains($needle, $haystack, $message = β€˜β€™)

  • param mixed $needle
  • param iterable<mixed> $haystack
  • param string $message
  • return void

Asserts that a haystack contains a needle.

See source