Expected
in package
Table of Contents
Methods
- atLeastOnce() : StubMarshaler
- Checks if a method has been invoked at least one time.
- exactly() : StubMarshaler
- Checks if a method has been invoked a certain amount of times.
- never() : StubMarshaler
- Checks if a method never has been invoked
- once() : StubMarshaler
- Checks if a method has been invoked exactly one time.
- closureIfNull() : mixed
Methods
atLeastOnce()
Checks if a method has been invoked at least one time.
public
static atLeastOnce([mixed $params = null ]) : StubMarshaler
If the number of invocations is 0 it will throw an exception in verify.
<?php
use \Codeception\Stub\Expected;
$user = $this->make(
'User',
array(
'getName' => Expected::atLeastOnce('Davert')),
'someMethod' => function() }
)
);
$user->getName();
$userName = $user->getName();
$this->assertEquals('Davert', $userName);
?>
Alternatively, a function can be passed as parameter:
<?php
Expected::atLeastOnce(function() { return Faker::name(); });
Parameters
- $params : mixed = null
Return values
StubMarshalerexactly()
Checks if a method has been invoked a certain amount of times.
public
static exactly(int $count[, mixed $params = null ]) : StubMarshaler
If the number of invocations exceeds the value it will immediately throw an exception, If the number is less it will later be checked in verify() and also throw an exception.
<?php
use \Codeception\Stub;
use \Codeception\Stub\Expected;
$user = $this->make(
'User',
array(
'getName' => Expected::exactly(3, 'Davert'),
'someMethod' => function() }
)
);
$user->getName();
$user->getName();
$userName = $user->getName();
$this->assertEquals('Davert', $userName);
?>
Alternatively, a function can be passed as parameter:
<?php
Expected::exactly(function() { return Faker::name() });
Parameters
- $count : int
- $params : mixed = null
Return values
StubMarshalernever()
Checks if a method never has been invoked
public
static never([mixed $params = null ]) : StubMarshaler
If method invoked, it will immediately throw an exception.
<?php
use \Codeception\Stub\Expected;
$user = $this->make('User', [
'getName' => Expected::never(),
'someMethod' => function() }
]);
$user->someMethod();
?>
Parameters
- $params : mixed = null
Return values
StubMarshaleronce()
Checks if a method has been invoked exactly one time.
public
static once([mixed $params = null ]) : StubMarshaler
If the number is less or greater it will later be checked in verify() and also throw an exception.
<?php
use \Codeception\Stub\Expected;
$user = $this->make(
'User',
array(
'getName' => Expected::once('Davert'),
'someMethod' => function() }
)
);
$userName = $user->getName();
$this->assertEquals('Davert', $userName);
?>
Alternatively, a function can be passed as parameter:
<?php
Expected::once(function() { return Faker::name(); });
Parameters
- $params : mixed = null
Return values
StubMarshalerclosureIfNull()
private
static closureIfNull(mixed $params) : mixed
Parameters
- $params : mixed