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);
Show file
Open project: php-mock/php-mock
Class Usage Examples
Method | Description | |
---|---|---|
build ( ) : |
Builds a mock. | |
setFunction ( callable $function ) : |
Sets the mock function. | |
setFunctionProvider ( phpmock\functions\FunctionProvider $provider ) : |
Sets the mock function. | |
setName ( string $name ) : |
Sets the mocked function name. | |
setNamespace ( string $namespace ) : |
Sets the mock namespace. |
public setFunction ( callable $function ) : |
||
$function | callable | The mock function. |
return |
public setFunctionProvider ( phpmock\functions\FunctionProvider $provider ) : |
||
$provider | phpmock\functions\FunctionProvider | The mock function provider. |
return |
public setNamespace ( string $namespace ) : |
||
$namespace | string | The function namespace. |
return |