Factory for mock object classes.
Mock
Mock
()
Clones a class' interface and creates a mock version that can have return values and expectations set.
void
generate
(string $class, [string $mock_class = false], [array $methods = false])
-
string
$class: Class to clone.
-
string
$mock_class: New class name. Default is the old name with "Mock" prepended.
-
array
$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.
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.
void
generatePartial
(string $class, string $mock_class, array $methods)
-
string
$class: Class to clone.
-
string
$mock_class: New class name.
-
array
$methods: Methods to be overridden with mock versions.
void
setMockBaseClass
([mixed $mock_base = false])
Creates source code for chaining to an aggregated mock object.
string
_chainMockExpectations
()
Creates source code for chaining to the composited mock object.
string
_chainMockReturns
()
The new mock class code as a string.
string
_createClassCode
(string $class, string $mock_class, array $methods)
-
string
$class: Class to clone.
-
string
$mock_class: New class name.
-
array
$methods: Additional methods.
The extension class code as a string. The class composites a mock object and chains mocked methods to it.
string
_extendClassCode
(string $class, string $mock_class, array $methods)
-
string
$class: Class to extend.
-
string
$mock_class: New class name.
-
array
$methods: Additional methods.
Creates source code to override a list of methods with mock versions.
string
_overrideMethods
(array $methods)
-
array
$methods: Methods to be overridden with mock versions.