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
파일 보기 프로젝트 열기: php-mock/php-mock 1 사용 예제들

공개 메소드들

메소드 설명
__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