Overview

Namespaces

  • phpmock
    • environment
    • functions
    • spy

Classes

  • Mock
  • MockBuilder

Interfaces

  • Deactivatable

Exceptions

  • MockEnabledException
  • Overview
  • Namespace
  • Class

Class MockBuilder

Fluent API mock builder.

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);
Namespace: phpmock
License: WTFPL
Author: Markus Malkusch markus@malkusch.de
See: phpmock\Mock
Link: Donations
Located at MockBuilder.php
Methods summary
public phpmock\MockBuilder
# setNamespace( string $namespace )

Sets the mock namespace.

Sets the mock namespace.

Parameters

$namespace
The function namespace.

Returns

phpmock\MockBuilder
public phpmock\MockBuilder
# setName( string $name )

Sets the mocked function name.

Sets the mocked function name.

Parameters

$name
The function name.

Returns

phpmock\MockBuilder
public phpmock\MockBuilder
# setFunction( callable $function )

Sets the mock function.

Sets the mock function.

Use this method if you want to set the mocked behaviour with a callable. Alternatively, you can use phpmock\MockBuilder::setFunctionProvider() to set it with a phpmock\functions\FunctionProvider.

Parameters

$function
The mock function.

Returns

phpmock\MockBuilder

See

phpmock\MockBuilder::setFunctionProvider()
public phpmock\MockBuilder
# setFunctionProvider( phpmock\functions\FunctionProvider $provider )

Sets the mock function.

Sets the mock function.

Use this method if you want to set the mocked behaviour with a phpmock\functions\FunctionProvider. Alternatively, you can use phpmock\MockBuilder::setFunction() to set it with a callable.

Parameters

$provider
The mock function provider.

Returns

phpmock\MockBuilder

See

phpmock\MockBuilder::setFunction()
public phpmock\Mock
# build( )

Builds a mock.

Builds a mock.

Returns

phpmock\Mock
The mock.
API documentation generated by ApiGen