Documentation

Expectation
in package
implements ExpectationInterface

Interfaces, Classes and Traits

ExpectationInterface

Table of Contents

$_actualCount  : int
Actual count of calls to this expectation
$_because  : string|null
Exception message
$_closureQueue  : array<string|int, mixed>
Array of closures executed with given arguments to generate a result to be returned
$_countValidatorClass  : string
The count validator class to use
$_countValidators  : array<string|int, mixed>
Count validator store
$_expectedArgs  : array<string|int, mixed>
Arguments expected by this expectation
$_globally  : bool
Flag indicating whether the order of calling is determined locally or globally
$_globalOrderNumber  : int
Integer representing the call order of this expectation on a global basis
$_mock  : LegacyMockInterface
Mock object to which this expectation belongs
$_name  : string
Method name
$_orderNumber  : int
Integer representing the call order of this expectation
$_passthru  : bool
Flag indicating if the return value should be obtained from the original class method instead of returning predefined values from the return queue
$_returnQueue  : array<string|int, mixed>
Array of return values as a queue for multiple return sequence
$_returnValue  : mixed
Value to return from this expectation
$_setQueue  : array<string|int, mixed>
Array of values to be set when this expectation matches
$_throw  : bool
Flag indicating that an exception is expected to be throw (not returned)
__clone()  : mixed
Cloning logic
__construct()  : mixed
Constructor
__toString()  : string
Return a string with the method name and arguments formatted
andReturn()  : self
Set a return value, or sequential queue of return values
andReturnArg()  : self
Sets up a closure to return the nth argument from the expected method call
andReturnFalse()  : mixed
andReturnNull()  : self
Return null. This is merely a language construct for Mock describing.
andReturns()  : self
Set a return value, or sequential queue of return values
andReturnSelf()  : self
Return this mock, like a fluent interface
andReturnTrue()  : mixed
andReturnUndefined()  : self
Return a self-returning black hole object.
andReturnUsing()  : self
Set a closure or sequence of closures with which to generate return values. The arguments passed to the expected method are passed to the closures as parameters.
andReturnValues()  : self
Set a sequential queue of return values with an array
andSet()  : self
Register values to be set to a public property each time this expectation occurs
andThrow()  : self
Set Exception class and arguments to that class to be thrown
andThrowExceptions()  : self
Set Exception classes to be thrown
andThrows()  : mixed
atLeast()  : self
Sets next count validator to the AtLeast instance
atMost()  : self
Sets next count validator to the AtMost instance
because()  : $this
Set the exception message
between()  : mixed
Shorthand for setting minimum and maximum constraints on call counts
byDefault()  : self
Mark this expectation as being a default
getExceptionMessage()  : mixed
getMock()  : LegacyMockInterface|MockInterface
Return the parent mock of the expectation
getName()  : mixed
getOrderNumber()  : int
Return order number
globally()  : self
Indicates call order should apply globally
isCallCountConstrained()  : bool
Check if there is a constraint on call count
isEligible()  : bool
Checks if this expectation is eligible for additional calls
matchArgs()  : bool
Check if passed arguments match an argument expectation
never()  : self
Indicates that this expectation is never expected to be called
once()  : self
Indicates that this expectation is expected exactly once
ordered()  : self
Indicates that this expectation must be called in a specific given order
passthru()  : self
Flag this expectation as calling the original class method with the any provided arguments instead of using a return value queue.
set()  : self
Alias to andSet(). Allows the natural English construct - set('foo', 'bar')->andReturn('bar')
times()  : self
Indicates the number of times this expectation should occur
twice()  : self
Indicates that this expectation is expected exactly twice
validateOrder()  : void
Verify call order
verify()  : void
Verify this expectation
verifyCall()  : mixed
Verify the current call, i.e. that the given arguments match those of this expectation
with()  : self
Expected argument setter for the expectation
withAnyArgs()  : self
Set expectation that any arguments are acceptable
withArgs()  : self
Expected arguments for the expectation passed as an array or a closure that matches each passed argument on each function call.
withNoArgs()  : self
Set with() as no arguments expected
withSomeOfArgs()  : self
Expected arguments should partially match the real arguments
zeroOrMoreTimes()  : self
Indicates this expectation should occur zero or more times
_defineOrdered()  : int
Setup the ordering tracking on the mock or mock container
_getReturnValue()  : mixed
Fetch the return value for the matching args
_matchArg()  : bool
Check if passed argument matches an argument expectation
_matchArgs()  : bool
Check if the passed arguments match the expectations, one by one.
_setValues()  : mixed
Sets public properties with queued values to the mock object
isAndAnyOtherArgumentsMatcher()  : mixed
isArgumentListMatcher()  : bool
Check if the registered expectation is an ArgumentListMatcher
throwAsNecessary()  : void
Throws an exception if the expectation has been configured to do so
withArgsInArray()  : self
Expected arguments for the expectation passed as an array
withArgsMatchedByClosure()  : self
Expected arguments have to be matched by the given closure.

Properties

$_actualCount

Actual count of calls to this expectation

protected int $_actualCount = 0

$_because

Exception message

protected string|null $_because = null

$_closureQueue

Array of closures executed with given arguments to generate a result to be returned

protected array<string|int, mixed> $_closureQueue = array()

$_countValidatorClass

The count validator class to use

protected string $_countValidatorClass = 'Mockery\CountValidator\Exact'

$_countValidators

Count validator store

protected array<string|int, mixed> $_countValidators = array()

$_expectedArgs

Arguments expected by this expectation

protected array<string|int, mixed> $_expectedArgs = array()

$_globally

Flag indicating whether the order of calling is determined locally or globally

protected bool $_globally = false

$_globalOrderNumber

Integer representing the call order of this expectation on a global basis

protected int $_globalOrderNumber = null

$_orderNumber

Integer representing the call order of this expectation

protected int $_orderNumber = null

$_passthru

Flag indicating if the return value should be obtained from the original class method instead of returning predefined values from the return queue

protected bool $_passthru = false

$_returnQueue

Array of return values as a queue for multiple return sequence

protected array<string|int, mixed> $_returnQueue = array()

$_returnValue

Value to return from this expectation

protected mixed $_returnValue = null

$_setQueue

Array of values to be set when this expectation matches

protected array<string|int, mixed> $_setQueue = array()

$_throw

Flag indicating that an exception is expected to be throw (not returned)

protected bool $_throw = false

Methods

__clone()

Cloning logic

public __clone() : mixed
Return values
mixed

__toString()

Return a string with the method name and arguments formatted

public __toString() : string
Return values
string

andReturn()

Set a return value, or sequential queue of return values

public andReturn(mixed ...$args) : self
Parameters
$args : mixed
Return values
self

andReturnArg()

Sets up a closure to return the nth argument from the expected method call

public andReturnArg(int $index) : self
Parameters
$index : int
Return values
self

andReturnFalse()

public andReturnFalse() : mixed
Return values
mixed

andReturnNull()

Return null. This is merely a language construct for Mock describing.

public andReturnNull() : self
Return values
self

andReturns()

Set a return value, or sequential queue of return values

public andReturns(mixed ...$args) : self
Parameters
$args : mixed
Return values
self

andReturnSelf()

Return this mock, like a fluent interface

public andReturnSelf() : self
Return values
self

andReturnTrue()

public andReturnTrue() : mixed
Return values
mixed

andReturnUndefined()

Return a self-returning black hole object.

public andReturnUndefined() : self
Return values
self

andReturnUsing()

Set a closure or sequence of closures with which to generate return values. The arguments passed to the expected method are passed to the closures as parameters.

public andReturnUsing(callable ...$args) : self
Parameters
$args : callable
Return values
self

andReturnValues()

Set a sequential queue of return values with an array

public andReturnValues(array<string|int, mixed> $values) : self
Parameters
$values : array<string|int, mixed>
Return values
self

andSet()

Register values to be set to a public property each time this expectation occurs

public andSet(string $name, array<string|int, mixed> ...$values) : self
Parameters
$name : string
$values : array<string|int, mixed>
Return values
self

andThrow()

Set Exception class and arguments to that class to be thrown

public andThrow(string|Exception $exception[, string $message = '' ], int $code[, Exception $previous = null ]) : self
Parameters
$exception : string|Exception
$message : string = ''
$code : int
$previous : Exception = null
Return values
self

andThrowExceptions()

Set Exception classes to be thrown

public andThrowExceptions(array<string|int, mixed> $exceptions) : self
Parameters
$exceptions : array<string|int, mixed>
Return values
self

andThrows()

public andThrows(mixed $exception[, mixed $message = '' ], mixed $code[, Exception $previous = null ]) : mixed
Parameters
$exception : mixed
$message : mixed = ''
$code : mixed
$previous : Exception = null
Return values
mixed

atLeast()

Sets next count validator to the AtLeast instance

public atLeast() : self
Return values
self

atMost()

Sets next count validator to the AtMost instance

public atMost() : self
Return values
self

because()

Set the exception message

public because(string $message) : $this
Parameters
$message : string
Return values
$this

between()

Shorthand for setting minimum and maximum constraints on call counts

public between(int $minimum, int $maximum) : mixed
Parameters
$minimum : int
$maximum : int
Return values
mixed

byDefault()

Mark this expectation as being a default

public byDefault() : self
Return values
self

getExceptionMessage()

public getExceptionMessage() : mixed
Return values
mixed

getName()

public getName() : mixed
Return values
mixed

getOrderNumber()

Return order number

public getOrderNumber() : int
Return values
int

globally()

Indicates call order should apply globally

public globally() : self
Return values
self

isCallCountConstrained()

Check if there is a constraint on call count

public isCallCountConstrained() : bool
Return values
bool

isEligible()

Checks if this expectation is eligible for additional calls

public isEligible() : bool
Return values
bool

matchArgs()

Check if passed arguments match an argument expectation

public matchArgs(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>
Return values
bool

never()

Indicates that this expectation is never expected to be called

public never() : self
Return values
self

once()

Indicates that this expectation is expected exactly once

public once() : self
Return values
self

ordered()

Indicates that this expectation must be called in a specific given order

public ordered([string $group = null ]) : self
Parameters
$group : string = null

Name of the ordered group

Return values
self

passthru()

Flag this expectation as calling the original class method with the any provided arguments instead of using a return value queue.

public passthru() : self
Return values
self

set()

Alias to andSet(). Allows the natural English construct - set('foo', 'bar')->andReturn('bar')

public set(string $name, mixed $value) : self
Parameters
$name : string
$value : mixed
Return values
self

times()

Indicates the number of times this expectation should occur

public times([int $limit = null ]) : self
Parameters
$limit : int = null
Tags
throws
InvalidArgumentException
Return values
self

twice()

Indicates that this expectation is expected exactly twice

public twice() : self
Return values
self

validateOrder()

Verify call order

public validateOrder() : void
Return values
void

verify()

Verify this expectation

public verify() : void
Return values
void

verifyCall()

Verify the current call, i.e. that the given arguments match those of this expectation

public verifyCall(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>
Return values
mixed

with()

Expected argument setter for the expectation

public with(mixed ...$args) : self
Parameters
$args : mixed
Return values
self

withAnyArgs()

Set expectation that any arguments are acceptable

public withAnyArgs() : self
Return values
self

withArgs()

Expected arguments for the expectation passed as an array or a closure that matches each passed argument on each function call.

public withArgs(array<string|int, mixed>|Closure $argsOrClosure) : self
Parameters
$argsOrClosure : array<string|int, mixed>|Closure
Return values
self

withNoArgs()

Set with() as no arguments expected

public withNoArgs() : self
Return values
self

withSomeOfArgs()

Expected arguments should partially match the real arguments

public withSomeOfArgs(mixed ...$expectedArgs) : self
Parameters
$expectedArgs : mixed
Return values
self

zeroOrMoreTimes()

Indicates this expectation should occur zero or more times

public zeroOrMoreTimes() : self
Return values
self

_defineOrdered()

Setup the ordering tracking on the mock or mock container

protected _defineOrdered(string $group, object $ordering) : int
Parameters
$group : string
$ordering : object
Return values
int

_getReturnValue()

Fetch the return value for the matching args

protected _getReturnValue(array<string|int, mixed> $args) : mixed
Parameters
$args : array<string|int, mixed>
Return values
mixed

_matchArg()

Check if passed argument matches an argument expectation

protected _matchArg(mixed $expected, mixed &$actual) : bool
Parameters
$expected : mixed
$actual : mixed
Return values
bool

_matchArgs()

Check if the passed arguments match the expectations, one by one.

protected _matchArgs(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>
Return values
bool

_setValues()

Sets public properties with queued values to the mock object

protected _setValues() : mixed
Return values
mixed

isAndAnyOtherArgumentsMatcher()

private isAndAnyOtherArgumentsMatcher(mixed $expectedArg) : mixed
Parameters
$expectedArg : mixed
Return values
mixed

isArgumentListMatcher()

Check if the registered expectation is an ArgumentListMatcher

private isArgumentListMatcher() : bool
Return values
bool

throwAsNecessary()

Throws an exception if the expectation has been configured to do so

private throwAsNecessary(mixed $return) : void
Parameters
$return : mixed
Tags
throws
Throwable
Return values
void

withArgsInArray()

Expected arguments for the expectation passed as an array

private withArgsInArray(array<string|int, mixed> $arguments) : self
Parameters
$arguments : array<string|int, mixed>
Return values
self

withArgsMatchedByClosure()

Expected arguments have to be matched by the given closure.

private withArgsMatchedByClosure(Closure $closure) : self
Parameters
$closure : Closure
Return values
self

Search results