PHP Class Scientist\Experiment

An experiment allows us to implement our code in a new way without risking the introduction of bugs or regressions.
Show file Open project: daylerees/scientist Class Usage Examples

Protected Properties

Property Type Description
$chance integer Execution chance.
$control callable The control callback.
$laboratory Laboratory Laboratory instance.
$matcher Scientist\Matchers\Matcher Matcher for experiment values.
$name string Experiment name.
$params array Parameters for our callbacks.
$trials array Trial callbacks.

Public Methods

Method Description
__construct ( string $name, Laboratory $laboratory ) Create a new experiment.
chance ( integer $chance ) Set the execution chance.
control ( callable $callback ) Register a control callback.
getChance ( ) : integer Get the execution chance.
getControl ( ) : callable Fetch the control callback.
getLaboratory ( ) : Laboratory | null Retrieve the laboratory instance.
getMatcher ( ) : Scientist\Matchers\Matcher Get the matcher for this experiment.
getName ( ) : string Fetch the experiment name.
getParams ( ) : array Get the experiment parameters.
getTrial ( string $name ) : mixed Fetch a trial callback by name.
getTrials ( ) : array Fetch an array of trial callbacks.
matcher ( Scientist\Matchers\Matcher $matcher ) Set a matcher for this experiment.
report ( ) : Report Execute the experiment and return a report.
run ( ) : mixed Execute the experiment within the laboratory.
shouldRun ( ) : boolean Determine whether an experiment should run based on chance.
trial ( string $name, callable $callback ) Register a trial callback.

Method Details

__construct() public method

Create a new experiment.
public __construct ( string $name, Laboratory $laboratory )
$name string
$laboratory Laboratory

chance() public method

Set the execution chance.
public chance ( integer $chance )
$chance integer

control() public method

Register a control callback.
public control ( callable $callback )
$callback callable

getChance() public method

Get the execution chance.
public getChance ( ) : integer
return integer

getControl() public method

Fetch the control callback.
public getControl ( ) : callable
return callable

getLaboratory() public method

Retrieve the laboratory instance.
public getLaboratory ( ) : Laboratory | null
return Laboratory | null

getMatcher() public method

Get the matcher for this experiment.
public getMatcher ( ) : Scientist\Matchers\Matcher
return Scientist\Matchers\Matcher

getName() public method

Fetch the experiment name.
public getName ( ) : string
return string

getParams() public method

Get the experiment parameters.
public getParams ( ) : array
return array

getTrial() public method

Fetch a trial callback by name.
public getTrial ( string $name ) : mixed
$name string
return mixed

getTrials() public method

Fetch an array of trial callbacks.
public getTrials ( ) : array
return array

matcher() public method

Set a matcher for this experiment.
public matcher ( Scientist\Matchers\Matcher $matcher )
$matcher Scientist\Matchers\Matcher

report() public method

Execute the experiment and return a report.
public report ( ) : Report
return Report

run() public method

Execute the experiment within the laboratory.
public run ( ) : mixed
return mixed

shouldRun() public method

Determine whether an experiment should run based on chance.
public shouldRun ( ) : boolean
return boolean

trial() public method

Register a trial callback.
public trial ( string $name, callable $callback )
$name string
$callback callable

Property Details

$chance protected property

Execution chance.
protected int $chance
return integer

$control protected property

The control callback.
protected callable $control
return callable

$laboratory protected property

Laboratory instance.
protected Laboratory,Scientist $laboratory
return Laboratory

$matcher protected property

Matcher for experiment values.
protected Matcher,Scientist\Matchers $matcher
return Scientist\Matchers\Matcher

$name protected property

Experiment name.
protected string $name
return string

$params protected property

Parameters for our callbacks.
protected array $params
return array

$trials protected property

Trial callbacks.
protected array $trials
return array