SimpleTest


SimpleTest\Mock
mock_objects.php at line 1079

Class Mock

Mock

public class Mock

Static methods only service class for code generation of mock objects.

Subpackage:
MockObjects

Constructor Summary

Mock()

Factory for mock object classes.

Method Summary
static void

generate(string class, string mock_class, array methods)

Clones a class' interface and creates a mock version that can have return values and expectations set.

static void

generatePartial(string class, string mock_class, array methods)

Generates a version of a class with selected methods mocked only.

static string

getExpectationLine(string format, array stack)

Uses a stack trace to find the line of an assertion.

Constructor Detail

mock_objects.php at line 1085

Mock

public Mock()

Factory for mock object classes.


Method Detail

mock_objects.php at line 1104

generate

public static void generate(string class, string mock_class, array methods)

Clones a class' interface and creates a mock version that can have return values and expectations set.

Parameters:
class - Class to clone.
mock_class - New class name. Default is the old name with "Mock" prepended.
methods - Additional methods to add beyond those in th cloned class. Use this to emulate the dynamic addition of methods in the cloned class or when the class hasn't been written yet.

mock_objects.php at line 1132

generatePartial

public static void generatePartial(string class, string mock_class, array methods)

Generates a version of a class with selected methods mocked only. Inherits the old class and chains the mock methods of an aggregated mock object.

Parameters:
class - Class to clone.
mock_class - New class name.
methods - Methods to be overridden with mock versions.

mock_objects.php at line 1316

getExpectationLine

public static string getExpectationLine(string format, array stack)

Uses a stack trace to find the line of an assertion.

Parameters:
format - String formatting.
stack - Stack frames top most first. Only needed if not using the PHP backtrace function.
Returns:
Line number of first expect* method embedded in format string.

SimpleTest