PHP Класс phpmock\Mock

Mocking a build-in PHP function is achieved by using PHP's namespace fallback policy. A mock will provide the namespaced function. I.e. only unqualified functions in a non-global namespace can be mocked. Example: namespace foo; use phpmock\Mock; $time = new Mock( __NAMESPACE__, "time", function () { return 3; } ); $time->enable(); assert (3 == time()); $time->disable(); assert (3 != time());
См. также: MockBuilder
Автор: Markus Malkusch ([email protected])
Наследование: implements phpmock\Deactivatable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( string $namespace, string $name, callable $function ) Set the namespace, function name and the mock function.
call ( array $arguments ) : mixed Calls the mocked function.
define ( ) Defines the mocked function in the given namespace.
disable ( ) Disable this mock.
disableAll ( ) Disable all mocks.
enable ( ) Enables this mock.
getFQFN ( ) : string Returns the fully qualified function name.
getName ( ) : string Returns the unqualified function name.
getNamespace ( ) : string Returns the namespace without enclosing slashes.

Описание методов

__construct() публичный Метод

Set the namespace, function name and the mock function.
public __construct ( string $namespace, string $name, callable $function )
$namespace string The namespace for the mock function.
$name string The function name of the mocked function.
$function callable The mock function.

call() публичный Метод

This method is called from the namespaced function.
public call ( array $arguments ) : mixed
$arguments array the call arguments.
Результат mixed

define() публичный Метод

In most cases you don't have to call this method. enable() is doing this for you. But if the mock is defined after the first call in the tested class, the tested class doesn't resolve to the mock. This is documented in Bug #68541. You therefore have to define the namespaced function before the first call. Defining the function has no side effects as you still have to enable the mock. If the function was already defined this method does nothing.
См. также: enable()
public define ( )

disable() публичный Метод

Disable this mock.
См. также: Mock::enable()
См. также: Mock::disableAll()
public disable ( )

disableAll() публичный статический Метод

Disable all mocks.
См. также: Mock::enable()
См. также: Mock::disable()
public static disableAll ( )

enable() публичный Метод

Enables this mock.
См. также: Mock::disable()
См. также: Mock::disableAll()
public enable ( )

getFQFN() публичный Метод

Returns the fully qualified function name.
public getFQFN ( ) : string
Результат string The function name with its namespace.

getName() публичный Метод

Returns the unqualified function name.
public getName ( ) : string
Результат string The name of the mocked function.

getNamespace() публичный Метод

Returns the namespace without enclosing slashes.
public getNamespace ( ) : string
Результат string The namespace