Testomatio - Test Management for Codeception
Declare mocks inside Codeception\Test\Unit
class.
If you want to use mocks outside it, check the reference for Codeception/Stub library.
template
RealInstanceType of objectparam
$classparam array
$params - properties and methods to setthrows RuntimeException
when class does not existthrows Exception
return MockObject&RealInstanceType
- mockInstantiates a class without executing a constructor.
Properties and methods can be set as a second parameter. Even protected and private properties can be set.
Accepts either name of class or object of that class
To replace method provide it’s name as a key in second parameter and it’s return value or callback function as parameter
template
RealInstanceType of objectparam
$classparam array
$paramsthrows Exception
return MockObject&RealInstanceType
Instantiates class having all methods replaced with dummies.
Constructor is not triggered. Properties and methods can be set as a second parameter. Even protected and private properties can be set.
Accepts either name of class or object of that class
To replace method provide it’s name as a key in second parameter and it’s return value or callback function as parameter
template
RealInstanceType of objectparam
$classparam string
$methodparam array
$paramsthrows Exception
return \PHPUnit\Framework\MockObject\MockObject&RealInstanceType
Instantiates class having all methods replaced with dummies except one.
Constructor is not triggered. Properties and methods can be replaced. Even protected and private properties can be set.
Accepts either name of class or object of that class
To replace method provide it’s name as a key in second parameter and it’s return value or callback function as parameter
template
RealInstanceType of objectparam
$classparam array
$constructorParamsparam array
$paramsthrows Exception
return MockObject&RealInstanceType
Instantiates a class instance by running constructor.
Parameters for constructor passed as second argument Properties and methods can be set in third argument. Even protected and private properties can be set.
Accepts either name of class or object of that class
To replace method provide it’s name as a key in third parameter and it’s return value or callback function as parameter
template
RealInstanceType of objectparam
$classparam array
$constructorParamsparam array
$paramsreturn MockObject&RealInstanceType
Instantiates a class instance by running constructor with all methods replaced with dummies.
Parameters for constructor passed as second argument Properties and methods can be set in third argument. Even protected and private properties can be set.
Accepts either name of class or object of that class
To replace method provide it’s name as a key in third parameter and it’s return value or callback function as parameter
To create a mock, pass current testcase name as last argument:
template
RealInstanceType of objectparam
$classparam string
$methodparam array
$constructorParamsparam array
$paramsthrows \ReflectionException
return MockObject&RealInstanceType
Instantiates a class instance by running constructor with all methods replaced with dummies, except one.
Parameters for constructor passed as second argument Properties and methods can be set in third argument. Even protected and private properties can be set.
Accepts either name of class or object of that class
To replace method provide it’s name as a key in third parameter and it’s return value or callback function as parameter
param mixed
$paramsreturn \Codeception\Stub\StubMarshaler
Checks if a method never has been invoked
If method invoked, it will immediately throw an exception.
param mixed
$paramsreturn \Codeception\Stub\StubMarshaler
Checks if a method has been invoked exactly one time.
If the number is less or greater it will later be checked in verify() and also throw an exception.
Alternatively, a function can be passed as parameter:
param mixed
$paramsreturn \Codeception\Stub\StubMarshaler
Checks if a method has been invoked at least one time.
If the number of invocations is 0 it will throw an exception in verify.
Alternatively, a function can be passed as parameter:
param int
$countparam mixed
$paramsreturn \Codeception\Stub\StubMarshaler
Checks if a method has been invoked a certain amount of times.
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.
Alternatively, a function can be passed as parameter: