Documentation

Log extends TestCase
in package

Provides utilities to test for log output.

Copyright 2011-2021 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Tags
category

Horde

author

Gunnar Wrobel wrobel@pardus.de

license

http://www.horde.org/licenses/lgpl21 LGPL

link
http://www.horde.org/components/Horde_Test

Table of Contents

$logHandler  : Horde_Log_Handler_Mock
The log handler.
assertLogContains()  : mixed
Asserts that the log contains at least one message matching the provided string.
assertLogCount()  : mixed
Asserts that the log contains the given number of messages.
assertLogRegExp()  : mixed
Asserts that the log contains at least one message matching the provided regular_expression.
getConfig()  : mixed
Helper method for loading test configuration from a file.
getLogger()  : Horde_Log_Logger
Returns a log handler.
getLogOutput()  : array<string|int, mixed>
Utility function to return the array of logged events.
getMockDependencies()  : MockDependencies
Create a MockDependencies instance from a class name to simplyfy creation of classes where all or most dependencies are mocked.
getMockSkipConstructor()  : mixed
Useful shorthand if you are mocking a class with a private constructor

Properties

$logHandler

The log handler.

private Horde_Log_Handler_Mock $logHandler

Methods

assertLogContains()

Asserts that the log contains at least one message matching the provided string.

public assertLogContains(string $message) : mixed

You MUST fetch the logger via $this->getLogger() before using this method. This will store a reference to an internal mock log handler that will later be used to analyze the log events.

Parameters
$message : string

The expected log message.

Return values
mixed

assertLogCount()

Asserts that the log contains the given number of messages.

public assertLogCount(int $count) : mixed

You MUST fetch the logger via $this->getLogger() before using this method. This will store a reference to an internal mock log handler that will later be used to analyze the log events.

Parameters
$count : int

The expected number of messages.

Return values
mixed

assertLogRegExp()

Asserts that the log contains at least one message matching the provided regular_expression.

public assertLogRegExp(string $regular_expression) : mixed

You MUST fetch the logger via $this->getLogger() before using this method. This will store a reference to an internal mock log handler that will later be used to analyze the log events.

Parameters
$regular_expression : string

The expected regular expression.

Return values
mixed

getConfig()

Helper method for loading test configuration from a file.

public static getConfig(string $env[, string $path = null ][, array<string|int, mixed> $default = array() ]) : mixed

The configuration can be specified by an environment variable. If the variable content is a file name, the configuration is loaded from the file. Otherwise it's assumed to be a json encoded configuration hash. If the environment variable is not set, the method tries to load a conf.php file from the same directory as the test case.

Parameters
$env : string

An environment variable name.

$path : string = null

The path to use.

$default : array<string|int, mixed> = array()

Some default values that are merged into the configuration if specified as a json hash.

Return values
mixed

The value of the configuration file's $conf variable, or null.

getLogger()

Returns a log handler.

public getLogger() : Horde_Log_Logger
Return values
Horde_Log_Logger

getLogOutput()

Utility function to return the array of logged events.

public getLogOutput() : array<string|int, mixed>
Return values
array<string|int, mixed>

getMockDependencies()

Create a MockDependencies instance from a class name to simplyfy creation of classes where all or most dependencies are mocked.

public getMockDependencies(string $class[, array<string|int, mixed> $overrides = [] ]) : MockDependencies
Parameters
$class : string

The full name of the class

$overrides : array<string|int, mixed> = []

Optional. Hashmap were the keys are the names of the parameters of the class and values are the instance to use. Every parameter not set here, will be automatically mocked instead

Tags
throws
Exception

If a parameter of the class does not have a type, no default value and is also not in the overrides array

Return values
MockDependencies

The MockDependencies instance that can be used to create instances of the class

getMockSkipConstructor()

Useful shorthand if you are mocking a class with a private constructor

public getMockSkipConstructor(mixed $className[, array<string|int, mixed> $methods = array() ][, array<string|int, mixed> $arguments = array() ][, mixed $mockClassName = '' ]) : mixed
Parameters
$className : mixed
$methods : array<string|int, mixed> = array()
$arguments : array<string|int, mixed> = array()
$mockClassName : mixed = ''
Return values
mixed

Search results