| layout | doc |
|---|---|
| title | Stub - Codeception - Documentation |
static
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.
{% highlight php %}
Stub::atLeastOnce(function() { return 'Davert';}), 'someMethod' => function() {} ) ); $user->getName(); $user->getName(); ?>{% endhighlight %}
-
param mixed$params -
returnStubMarshaler
static
Stubbing a method call to return a list of values in the specified order.
{% highlight php %}
Stub::consecutive('david', 'emma', 'sam', 'amy'))); $user->getName(); //david $user->getName(); //emma $user->getName(); //sam $user->getName(); //amy ?>{% endhighlight %}
returnConsecutiveMap
static
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.
{% highlight php %}
false)); Stub::construct('User', array('autosave' => false), array('name' => 'davert')); ?>{% endhighlight %}
Accepts either name of class or object of that class
{% highlight php %}
false), array('name' => 'davert')); ?>{% endhighlight %}
To replace method provide it's name as a key in third parameter and it's return value or callback function as parameter
{% highlight php %}
function () { return true; })); Stub::construct('User', array(), array('save' => true })); ?>{% endhighlight %}
-
param mixed$class -
param array$constructorParams -
param array$params -
param bool|\PHPUnit_Framework_TestCase$testCase -
returnobject
static
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.
{% highlight php %}
false)); Stub::constructEmpty('User', array('autosave' => false), array('name' => 'davert')); ?>{% endhighlight %}
Accepts either name of class or object of that class
{% highlight php %}
false), array('name' => 'davert')); ?>{% endhighlight %}
To replace method provide it's name as a key in third parameter and it's return value or callback function as parameter
{% highlight php %}
function () { return true; })); Stub::constructEmpty('User', array(), array('save' => true })); ?>{% endhighlight %}
-
param mixed$class -
param array$constructorParams -
param array$params -
param bool|\PHPUnit_Framework_TestCase$testCase -
returnobject
static
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.
{% highlight php %}
false), array('name' => 'davert')); ?>{% endhighlight %}
Accepts either name of class or object of that class
{% highlight php %}
false), array('name' => 'davert')); ?>{% endhighlight %}
To replace method provide it's name as a key in third parameter and it's return value or callback function as parameter
{% highlight php %}
function () { return true; })); Stub::constructEmptyExcept('User', 'save', array(), array('save' => true })); ?>{% endhighlight %}
-
param mixed$class -
param string$method -
param array$constructorParams -
param array$params -
param bool|\PHPUnit_Framework_TestCase$testCase -
returnobject
static
Clones an object and redefines it's properties (even protected and private)
-
param$obj -
param array$params -
returnmixed
static
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.
{% highlight php %}
Stub::exactly(3, function() { return 'Davert';}), 'someMethod' => function() {} ) ); $user->getName(); $user->getName(); $user->getName(); ?>{% endhighlight %}
-
param int$count -
param mixed$params -
returnStubMarshaler
static
Creates $num instances of class through Stub::make.
-
param mixed$class -
param int$num -
param array$params -
returnarray
static
Instantiates a class without executing a constructor. Properties and methods can be set as a second parameter. Even protected and private properties can be set.
{% highlight php %}
'davert')); ?>{% endhighlight %}
Accepts either name of class or object of that class
{% highlight php %}
'davert')); ?>{% endhighlight %}
To replace method provide it's name as a key in second parameter and it's return value or callback function as parameter
{% highlight php %}
function () { return true; })); Stub::make('User', array('save' => true })); ?>{% endhighlight %}
-
param mixed$class - A class to be mocked -
param array$params - properties and methods to set -
param bool|\PHPUnit_Framework_TestCase$testCase -
returnobject - mock -
throws\RuntimeException when class does not exist
static
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.
{% highlight php %}
'davert')); ?>{% endhighlight %}
Accepts either name of class or object of that class
{% highlight php %}
'davert')); ?>{% endhighlight %}
To replace method provide it's name as a key in second parameter and it's return value or callback function as parameter
{% highlight php %}
function () { return true; })); Stub::makeEmpty('User', array('save' => true })); ?>{% endhighlight %}
-
param mixed$class -
param array$params -
param bool|\PHPUnit_Framework_TestCase$testCase -
returnobject
static
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.
{% highlight php %}
'davert')); ?>{% endhighlight %}
Accepts either name of class or object of that class
{% highlight php %}
{% endhighlight %}
To replace method provide it's name as a key in second parameter and it's return value or callback function as parameter
{% highlight php %}
function () { return true; })); Stub::makeEmptyExcept('User', 'save', array('isValid' => true })); ?>{% endhighlight %}
-
param mixed$class -
param string$method -
param array$params -
param bool|\PHPUnit_Framework_TestCase$testCase -
returnobject
static
Checks if a method never has been invoked
If method invoked, it will immediately throw an exception.
{% highlight php %}
Stub::never(), 'someMethod' => function() {})); $user->someMethod(); ?>{% endhighlight %}
-
param mixed$params -
returnStubMarshaler
static
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.
{% highlight php %}
Stub::once(function() { return 'Davert';}), 'someMethod' => function() {} ) ); $userName = $user->getName(); $this->assertEquals('Davert', $userName); ?>{% endhighlight %}
-
param mixed$params -
returnStubMarshaler
static
Replaces properties of current stub
-
param \PHPUnit_Framework_MockObject_MockObject$mock -
param array$params -
returnmixed -
throws\LogicException