PHP Class phpmock\MockBuilder

Example: namespace foo; use phpmock\MockBuilder; use phpmock\functions\FixedValueFunction; $builder = new MockBuilder(); $builder->setNamespace(__NAMESPACE__) ->setName("time") ->setFunctionProvider(new FixedValueFunction(1417011228)); $mock = $builder->build(); The mock is not enabled yet. assert (time() != 1417011228); $mock->enable(); assert (time() == 1417011228); The mock is disabled and PHP's built-in time() is called. $mock->disable(); assert (time() != 1417011228);
See also: Mock
Author: Markus Malkusch ([email protected])
Mostrar archivo Open project: php-mock/php-mock Class Usage Examples

Public Methods

Method Description
build ( ) : Mock Builds a mock.
setFunction ( callable $function ) : MockBuilder Sets the mock function.
setFunctionProvider ( phpmock\functions\FunctionProvider $provider ) : MockBuilder Sets the mock function.
setName ( string $name ) : MockBuilder Sets the mocked function name.
setNamespace ( string $namespace ) : MockBuilder Sets the mock namespace.

Method Details

build() public method

Builds a mock.
public build ( ) : Mock
return Mock The mock.

setFunction() public method

Use this method if you want to set the mocked behaviour with a callable. Alternatively, you can use {@link setFunctionProvider()} to set it with a {@link FunctionProvider}.
See also: setFunctionProvider()
public setFunction ( callable $function ) : MockBuilder
$function callable The mock function.
return MockBuilder

setFunctionProvider() public method

Use this method if you want to set the mocked behaviour with a {@link FunctionProvider}. Alternatively, you can use {@link setFunction()} to set it with a callable.
See also: setFunction()
public setFunctionProvider ( phpmock\functions\FunctionProvider $provider ) : MockBuilder
$provider phpmock\functions\FunctionProvider The mock function provider.
return MockBuilder

setName() public method

Sets the mocked function name.
public setName ( string $name ) : MockBuilder
$name string The function name.
return MockBuilder

setNamespace() public method

Sets the mock namespace.
public setNamespace ( string $namespace ) : MockBuilder
$namespace string The function namespace.
return MockBuilder