HumHub Documentation (unofficial)

Asserts extends AbstractAsserts
in package

Special module for using asserts in your tests.

Table of Contents

Properties

$aliases  : array<string|int, mixed>
Allows to rename actions
$excludeActions  : array<string|int, mixed>
Allows to explicitly exclude actions from module.
$includeInheritedActions  : bool
By setting it to false module wan't inherit methods of parent class.
$onlyActions  : array<string|int, mixed>
Allows to explicitly set what methods have this class.
$backupConfig  : mixed
$config  : mixed
$moduleContainer  : ModuleContainer
$requiredFields  : mixed
$storage  : mixed

Methods

__construct()  : mixed
Module constructor.
_after()  : mixed
**HOOK** executed after test
_afterStep()  : mixed
**HOOK** executed after step
_afterSuite()  : mixed
**HOOK** executed after suite
_before()  : mixed
**HOOK** executed before test
_beforeStep()  : mixed
**HOOK** executed before step
_beforeSuite()  : mixed
**HOOK** executed before suite
_failed()  : mixed
**HOOK** executed when test fails but before `_after`
_getConfig()  : mixed
Get config values or specific config item.
_getName()  : string
Returns a module name for a Module, a class name for Helper
_hasRequiredFields()  : bool
Checks if a module has required fields
_initialize()  : mixed
**HOOK** triggered after module is created and configuration is loaded
_reconfigure()  : mixed
Allows to redefine config for a specific test.
_resetConfig()  : mixed
Reverts config changed by `_reconfigure`
_setConfig()  : mixed
Allows to define initial module config.
expectException()  : mixed
Handles and checks exception called inside callback function.
expectThrowable()  : mixed
Handles and checks throwables (Exceptions/Errors) called inside the callback function.
assert()  : mixed
assertFileNotExists()  : mixed
Asserts that a file does not exist.
assertGreaterOrEquals()  : mixed
Asserts that a value is greater than or equal to another value.
assertIsEmpty()  : mixed
Asserts that a variable is empty.
assertLessOrEquals()  : mixed
Asserts that a value is smaller than or equal to another value.
assertNot()  : mixed
assertNotRegExp()  : mixed
Asserts that a string does not match a given regular expression.
assertRegExp()  : mixed
Asserts that a string matches a given regular expression.
assertThatItsNot()  : mixed
Evaluates a PHPUnit\Framework\Constraint matcher object.
checkThrowable()  : mixed
Check if the given throwable matches the expected data, fail (throws an exception) if it does not.
debug()  : mixed
Print debug message to the screen.
debugSection()  : mixed
Print debug message with a title
getModule()  : Module
Get another module by its name:
getModules()  : array<string|int, mixed>
Get all enabled modules
hasModule()  : bool
Checks that module is enabled.
onReconfigure()  : mixed
HOOK to be executed when config changes with `_reconfigure`.
scalarizeArray()  : mixed
shortenMessage()  : string
Short text message to an amount of chars
validateConfig()  : mixed
Validates current config for required fields and required packages.

Properties

$aliases

Allows to rename actions

public static array<string|int, mixed> $aliases = []

$excludeActions

Allows to explicitly exclude actions from module.

public static array<string|int, mixed> $excludeActions = []

$includeInheritedActions

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

public static bool $includeInheritedActions = true

$onlyActions

Allows to explicitly set what methods have this class.

public static array<string|int, mixed> $onlyActions = []

$backupConfig

protected mixed $backupConfig = []

$config

protected mixed $config = []

$requiredFields

protected mixed $requiredFields = []

$storage

protected mixed $storage = []

Methods

__construct()

Module constructor.

public __construct(ModuleContainer $moduleContainer[, array<string|int, mixed>|null $config = null ]) : mixed

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

Parameters
$moduleContainer : ModuleContainer
$config : array<string|int, mixed>|null = null

_afterStep()

**HOOK** executed after step

public _afterStep(Step $step) : mixed
Parameters
$step : Step

_afterSuite()

**HOOK** executed after suite

public _afterSuite() : mixed

_beforeStep()

**HOOK** executed before step

public _beforeStep(Step $step) : mixed
Parameters
$step : Step

_beforeSuite()

**HOOK** executed before suite

public _beforeSuite([array<string|int, mixed> $settings = [] ]) : mixed
Parameters
$settings : array<string|int, mixed> = []

_failed()

**HOOK** executed when test fails but before `_after`

public _failed(TestInterface $test, Exception $fail) : mixed
Parameters
$test : TestInterface
$fail : Exception

_getConfig()

Get config values or specific config item.

public _getConfig([mixed $key = null ]) : mixed
Parameters
$key : mixed = null
Return values
mixed

the config item's value or null if it doesn't exist

_getName()

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

public _getName() : string
Return values
string

_hasRequiredFields()

Checks if a module has required fields

public _hasRequiredFields() : bool
Return values
bool

_initialize()

**HOOK** triggered after module is created and configuration is loaded

public _initialize() : mixed

_reconfigure()

Allows to redefine config for a specific test.

public _reconfigure(mixed $config) : mixed

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]);
    }
}
Parameters
$config : mixed
Tags
throws
ModuleConfigException
throws
ModuleException

_resetConfig()

Reverts config changed by `_reconfigure`

public _resetConfig() : mixed

_setConfig()

Allows to define initial module config.

public _setConfig(mixed $config) : mixed

Can be used in _beforeSuite hook of Helpers or Extensions

<?php
public function _beforeSuite($settings = []) {
    $this->getModule('otherModule')->_setConfig($this->myOtherConfig);
}
Parameters
$config : mixed
Tags
throws
ModuleConfigException
throws
ModuleException

expectException()

Handles and checks exception called inside callback function.

public expectException(Exception|string $exception, callable $callback) : mixed

Either exception class name or exception instance should be provided.

<?php
$I->expectException(MyException::class, function() {
    $this->doSomethingBad();
});

$I->expectException(new MyException(), function() {
    $this->doSomethingBad();
});

If you want to check message or exception code, you can pass them with exception instance:

<?php
// will check that exception MyException is thrown with "Don't do bad things" message
$I->expectException(new MyException("Don't do bad things"), function() {
    $this->doSomethingBad();
});
Parameters
$exception : Exception|string
$callback : callable
Tags
deprecated

Use expectThrowable() instead

expectThrowable()

Handles and checks throwables (Exceptions/Errors) called inside the callback function.

public expectThrowable(Throwable|string $throwable, callable $callback) : mixed

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();
});
Parameters
$throwable : Throwable|string
$callback : callable

assert()

protected assert(mixed $arguments[, bool $not = false ]) : mixed
Parameters
$arguments : mixed
$not : bool = false

assertFileNotExists()

Asserts that a file does not exist.

protected assertFileNotExists(string $filename[, string $message = '' ]) : mixed
Parameters
$filename : string
$message : string = ''

assertGreaterOrEquals()

Asserts that a value is greater than or equal to another value.

protected assertGreaterOrEquals(mixed $expected, mixed $actual[, string $message = '' ]) : mixed
Parameters
$expected : mixed
$actual : mixed
$message : string = ''

assertIsEmpty()

Asserts that a variable is empty.

protected assertIsEmpty(mixed $actual[, string $message = '' ]) : mixed
Parameters
$actual : mixed
$message : string = ''

assertLessOrEquals()

Asserts that a value is smaller than or equal to another value.

protected assertLessOrEquals(mixed $expected, mixed $actual[, string $message = '' ]) : mixed
Parameters
$expected : mixed
$actual : mixed
$message : string = ''

assertNot()

protected assertNot(mixed $arguments) : mixed
Parameters
$arguments : mixed

assertNotRegExp()

Asserts that a string does not match a given regular expression.

protected assertNotRegExp(string $pattern, string $string[, string $message = '' ]) : mixed
Parameters
$pattern : string
$string : string
$message : string = ''

assertRegExp()

Asserts that a string matches a given regular expression.

protected assertRegExp(string $pattern, string $string[, string $message = '' ]) : mixed
Parameters
$pattern : string
$string : string
$message : string = ''

assertThatItsNot()

Evaluates a PHPUnit\Framework\Constraint matcher object.

protected assertThatItsNot(mixed $value, Constraint $constraint[, string $message = '' ]) : mixed
Parameters
$value : mixed
$constraint : Constraint
$message : string = ''

checkThrowable()

Check if the given throwable matches the expected data, fail (throws an exception) if it does not.

protected checkThrowable(Throwable $throwable, string $expectedClass, string $expectedMsg, int $expectedCode) : mixed
Parameters
$throwable : Throwable
$expectedClass : string
$expectedMsg : string
$expectedCode : int

debug()

Print debug message to the screen.

protected debug(mixed $message) : mixed
Parameters
$message : mixed

debugSection()

Print debug message with a title

protected debugSection(mixed $title, mixed $message) : mixed
Parameters
$title : mixed
$message : mixed

getModule()

Get another module by its name:

protected getModule(mixed $name) : Module
<?php
$this->getModule('WebDriver')->_findElements('.items');
Parameters
$name : mixed
Tags
throws
ModuleException
Return values
Module

getModules()

Get all enabled modules

protected getModules() : array<string|int, mixed>
Return values
array<string|int, mixed>

hasModule()

Checks that module is enabled.

protected hasModule(mixed $name) : bool
Parameters
$name : mixed
Return values
bool

onReconfigure()

HOOK to be executed when config changes with `_reconfigure`.

protected onReconfigure() : mixed

scalarizeArray()

protected scalarizeArray(mixed $array) : mixed
Parameters
$array : mixed

shortenMessage()

Short text message to an amount of chars

protected shortenMessage(mixed $message[, mixed $chars = 150 ]) : string
Parameters
$message : mixed
$chars : mixed = 150
Return values
string

        
On this page

Search results