Oihana PHP

MockTrait

Provides a `mock` flag allowing a controller to switch its underlying model into a test/mock mode.

The flag is typically used to return fabricated data instead of querying the real data source, which is convenient for tests and previews.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Properties

$mock  : bool
The mock flag to test the model.

Methods

initializeMock()  : static
Initialize the `mock` property.

Properties

$mock

The mock flag to test the model.

public bool $mock = null

Methods

initializeMock()

Initialize the `mock` property.

public initializeMock([bool|array<string|int, mixed> $init = [] ]) : static

The flag is read directly when $init is a boolean, otherwise from the ControllerParam::MOCK key of the initialization array (defaulting to null).

Parameters
$init : bool|array<string|int, mixed> = []

Optional initialization array or the mock boolean value.

Return values
static

Returns the current instance for method chaining.

On this page

Search results