PHP Class Mockery\Expectation

Inheritance: implements mockery\ExpectationInterface
显示文件 Open project: padraic/mockery Class Usage Examples

Protected Properties

Property Type Description
$_actualCount integer Actual count of calls to this expectation
$_closureQueue array Array of closures executed with given arguments to generate a result to be returned
$_countValidatorClass string The count validator class to use
$_countValidators array Count validator store
$_expectedArgs array Arguments expected by this expectation
$_globalOrderNumber integer Integer representing the call order of this expectation on a global basis
$_globally boolean Flag indicating whether the order of calling is determined locally or globally
$_mock object Mock object to which this expectation belongs
$_name string Method name
$_noArgsExpectation boolean Flag indicating we expect no arguments
$_orderNumber integer Integer representing the call order of this expectation
$_passthru boolean 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 Array of return values as a queue for multiple return sequence
$_returnValue mixed Value to return from this expectation
$_setQueue array Array of values to be set when this expectation matches
$_throw boolean Flag indicating that an exception is expected to be throw (not returned)

Public Methods

Method Description
__clone ( ) Cloning logic
__construct ( Mockery\MockInterface $mock, string $name ) 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
andReturnFalse ( )
andReturnNull ( ) : self Return null. This is merely a language construct for Mock describing.
andReturnSelf ( ) : self Return this mock, like a fluent interface
andReturnTrue ( )
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 ( array $values ) : self Set a sequential queue of return values with an array
andSet ( string $name, mixed $value ) : self Register values to be set to a public property each time this expectation occurs
andThrow ( string | Exception $exception, string $message = '', integer $code, Exception $previous = null ) : self Set Exception class and arguments to that class to be thrown
andThrowExceptions ( array $exceptions ) : self Set Exception classes to be thrown
atLeast ( ) : self Sets next count validator to the AtLeast instance
atMost ( ) : self Sets next count validator to the AtMost instance
between ( integer $minimum, integer $maximum ) Shorthand for setting minimum and maximum constraints on call counts
byDefault ( ) : self Mark this expectation as being a default
getMock ( ) : Mockery\MockInterface Return the parent mock of the expectation
getName ( )
getOrderNumber ( ) : integer Return order number
globally ( ) : self Indicates call order should apply globally
isCallCountConstrained ( ) : boolean Check if there is a constraint on call count
isEligible ( ) : boolean Checks if this expectation is eligible for additional calls
matchArgs ( array $args ) : boolean 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 ( string $group = null ) : 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 ( string $name, mixed $value ) : self Alias to andSet(). Allows the natural English construct - set('foo', 'bar')->andReturn('bar')
times ( integer $limit = null ) : 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 ( ) : boolean Verify this expectation
verifyCall ( array $args ) : 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 ( array | Closur\Closure $argsOrClosure ) : 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
zeroOrMoreTimes ( ) : self Indicates this expectation should occur zero or more times

Protected Methods

Method Description
_defineOrdered ( string $group, object $ordering ) : integer Setup the ordering tracking on the mock or mock container
_getReturnValue ( array $args ) : mixed Fetch the return value for the matching args
_matchArg ( mixed $expected, &$actual ) : boolean Check if passed argument matches an argument expectation
_setValues ( ) : mixed Sets public properties with queued values to the mock object

Private Methods

Method Description
isMultiArgumentClosureExpectation ( ) : boolean Check if the registered expectation is a MultiArgumentClosureExpectation.
withArgsInArray ( array $arguments ) : self Expected arguments for the expectation passed as an array
withArgsMatchedByClosure ( Closur\Closure $closure ) : self Expected arguments have to be matched by the given closure.

Method Details

__clone() public method

Cloning logic
public __clone ( )

__construct() public method

Constructor
public __construct ( Mockery\MockInterface $mock, string $name )
$mock Mockery\MockInterface
$name string

__toString() public method

Return a string with the method name and arguments formatted
public __toString ( ) : string
return string

_defineOrdered() protected method

Setup the ordering tracking on the mock or mock container
protected _defineOrdered ( string $group, object $ordering ) : integer
$group string
$ordering object
return integer

_getReturnValue() protected method

Fetch the return value for the matching args
protected _getReturnValue ( array $args ) : mixed
$args array
return mixed

_matchArg() protected method

Check if passed argument matches an argument expectation
protected _matchArg ( mixed $expected, &$actual ) : boolean
$expected mixed
return boolean

_setValues() protected method

Sets public properties with queued values to the mock object
protected _setValues ( ) : mixed
return mixed

andReturn() public method

Set a return value, or sequential queue of return values
public andReturn ( ) : self
return self

andReturnFalse() public method

public andReturnFalse ( )

andReturnNull() public method

Return null. This is merely a language construct for Mock describing.
public andReturnNull ( ) : self
return self

andReturnSelf() public method

Return this mock, like a fluent interface
public andReturnSelf ( ) : self
return self

andReturnTrue() public method

public andReturnTrue ( )

andReturnUndefined() public method

Return a self-returning black hole object.
public andReturnUndefined ( ) : self
return self

andReturnUsing() public method

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 ( ) : self
return self

andReturnValues() public method

Set a sequential queue of return values with an array
public andReturnValues ( array $values ) : self
$values array
return self

andSet() public method

Register values to be set to a public property each time this expectation occurs
public andSet ( string $name, mixed $value ) : self
$name string
$value mixed
return self

andThrow() public method

Set Exception class and arguments to that class to be thrown
public andThrow ( string | Exception $exception, string $message = '', integer $code, Exception $previous = null ) : self
$exception string | Exception
$message string
$code integer
$previous Exception
return self

andThrowExceptions() public method

Set Exception classes to be thrown
public andThrowExceptions ( array $exceptions ) : self
$exceptions array
return self

atLeast() public method

Sets next count validator to the AtLeast instance
public atLeast ( ) : self
return self

atMost() public method

Sets next count validator to the AtMost instance
public atMost ( ) : self
return self

between() public method

Shorthand for setting minimum and maximum constraints on call counts
public between ( integer $minimum, integer $maximum )
$minimum integer
$maximum integer

byDefault() public method

Mark this expectation as being a default
public byDefault ( ) : self
return self

getMock() public method

Return the parent mock of the expectation
public getMock ( ) : Mockery\MockInterface
return Mockery\MockInterface

getName() public method

public getName ( )

getOrderNumber() public method

Return order number
public getOrderNumber ( ) : integer
return integer

globally() public method

Indicates call order should apply globally
public globally ( ) : self
return self

isCallCountConstrained() public method

Check if there is a constraint on call count
public isCallCountConstrained ( ) : boolean
return boolean

isEligible() public method

Checks if this expectation is eligible for additional calls
public isEligible ( ) : boolean
return boolean

matchArgs() public method

Check if passed arguments match an argument expectation
public matchArgs ( array $args ) : boolean
$args array
return boolean

never() public method

Indicates that this expectation is never expected to be called
public never ( ) : self
return self

once() public method

Indicates that this expectation is expected exactly once
public once ( ) : self
return self

ordered() public method

Indicates that this expectation must be called in a specific given order
public ordered ( string $group = null ) : self
$group string Name of the ordered group
return self

passthru() public method

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 self

set() public method

Alias to andSet(). Allows the natural English construct - set('foo', 'bar')->andReturn('bar')
public set ( string $name, mixed $value ) : self
$name string
$value mixed
return self

times() public method

Indicates the number of times this expectation should occur
public times ( integer $limit = null ) : self
$limit integer
return self

twice() public method

Indicates that this expectation is expected exactly twice
public twice ( ) : self
return self

validateOrder() public method

Verify call order
public validateOrder ( ) : void
return void

verify() public method

Verify this expectation
public verify ( ) : boolean
return boolean

verifyCall() public method

Verify the current call, i.e. that the given arguments match those of this expectation
public verifyCall ( array $args ) : mixed
$args array
return mixed

with() public method

Expected argument setter for the expectation
public with ( ) : self
return self

withAnyArgs() public method

Set expectation that any arguments are acceptable
public withAnyArgs ( ) : self
return self

withArgs() public method

Expected arguments for the expectation passed as an array or a closure that matches each passed argument on each function call.
public withArgs ( array | Closur\Closure $argsOrClosure ) : self
$argsOrClosure array | Closur\Closure
return self

withNoArgs() public method

Set with() as no arguments expected
public withNoArgs ( ) : self
return self

zeroOrMoreTimes() public method

Indicates this expectation should occur zero or more times
public zeroOrMoreTimes ( ) : self
return self

Property Details

$_actualCount protected_oe property

Actual count of calls to this expectation
protected int $_actualCount
return integer

$_closureQueue protected_oe property

Array of closures executed with given arguments to generate a result to be returned
protected array $_closureQueue
return array

$_countValidatorClass protected_oe property

The count validator class to use
protected string $_countValidatorClass
return string

$_countValidators protected_oe property

Count validator store
protected array $_countValidators
return array

$_expectedArgs protected_oe property

Arguments expected by this expectation
protected array $_expectedArgs
return array

$_globalOrderNumber protected_oe property

Integer representing the call order of this expectation on a global basis
protected int $_globalOrderNumber
return integer

$_globally protected_oe property

Flag indicating whether the order of calling is determined locally or globally
protected bool $_globally
return boolean

$_mock protected_oe property

Mock object to which this expectation belongs
protected object $_mock
return object

$_name protected_oe property

Method name
protected string $_name
return string

$_noArgsExpectation protected_oe property

Flag indicating we expect no arguments
protected bool $_noArgsExpectation
return boolean

$_orderNumber protected_oe property

Integer representing the call order of this expectation
protected int $_orderNumber
return integer

$_passthru protected_oe property

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
return boolean

$_returnQueue protected_oe property

Array of return values as a queue for multiple return sequence
protected array $_returnQueue
return array

$_returnValue protected_oe property

Value to return from this expectation
protected mixed $_returnValue
return mixed

$_setQueue protected_oe property

Array of values to be set when this expectation matches
protected array $_setQueue
return array

$_throw protected_oe property

Flag indicating that an exception is expected to be throw (not returned)
protected bool $_throw
return boolean