Skip to content

Commit 56771a7

Browse files
committed
fix to stubs
1 parent 51bdfd1 commit 56771a7

File tree

2 files changed

+57
-54
lines changed

2 files changed

+57
-54
lines changed

_posts/2012-10-22-xml-rpc-release

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Also, we did some changes for 2-steps tests loading, intrudoced in 1.1. At the f
3636

3737
### Minor Features and Bugfixes
3838

39+
* Composer package fixed
3940
* `grabServiceFromContainer` method added to Symfony2 module
4041
* REST [fixes](https://github.com/Codeception/Codeception/pull/75) and [improvements](https://github.com/Codeception/Codeception/pull/71) by **tiger-seo**
4142
* Fix for using `seeInDatabase` command with PostgreSQL

docs/reference/stubs.markdown

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
1-
---
2-
layout: page
3-
title: Codeception Stubs
4-
---
5-
6-
# Stub
7-
8-
Class for easily create stubs in your unit tests. You can use this class even inside PHPUnit tests too. It's a useful wrapper on top of PHPUnit mock builder.
9-
10-
### Usage
11-
12-
* `make` - creates new class bypassing constructor
13-
* `makeEmpty` - creates new class bypassing constructor with all methods return null.
14-
* `construct` - creates new class throgh constructor.
15-
* `constructEmpty` - creates new empty class throgh constructor with all methods return null.
16-
* `copy` - copies object and redefines it's properties.
17-
18-
### Example
19-
20-
{% highlight php %}
21-
use \Codeception\Util\Stub as Stub;
22-
23-
// create class instance with name set method 'save' redefined.
24-
$user = Stub::make('User', array('name' => 'davert', 'save' => function () { return true; }));
25-
26-
// create class instance with all empty methods (will return NULL)
27-
$user = Stub::makeEmpty('User', array('getName' => function () { return 'davert'; }));
28-
$user->save(); // is empty and returns NULL
29-
$user->getName(); // return 'davert'
30-
31-
// create class with empty methods except one
32-
$user = Stub::makeEmptyExcept('User', 'getName', array('name' => 'davert'));
33-
$user->save(); // is empty and returns NULL
34-
$user->getName(); // returns 'davert'
35-
36-
// create class instance through constructor
37-
// second parameter is array, it's values will be passed to constructor.
38-
39-
// similar to $user = new User($con, $is_new);
40-
$user = Stub::construct('User', array($con, $is_new), array('name' => 'davert'));
41-
42-
// similar is constructEmpty
43-
$user = Stub::constructEmpty('User', array($con, $is_new), array('getName' => function () { return 'davert'; }));
44-
45-
// and constructEmptyExcept
46-
$user = Stub::constructEmptyExcept('User', 'getName', array($con, $is_new), array('name' => 'davert'));
47-
48-
// copy and redefine class instance
49-
// can act with regular objects, not only stubs
50-
$user->getName(); // returns 'davert'
51-
$user2 = Stub::copy($user, array('name' => 'davert2'));
52-
$user->getName(); // returns 'davert2'
53-
{% endhighlight %}
54-
1+
---
2+
layout: page
3+
title: Codeception Stubs
4+
---
5+
6+
# Stub
7+
8+
Class for easily create stubs in your unit tests. You can use this class even inside PHPUnit tests too. It's a useful wrapper on top of PHPUnit mock builder.
9+
10+
### Usage
11+
12+
* `make` - creates new class bypassing constructor
13+
* `makeEmpty` - creates new class bypassing constructor with all methods return null.
14+
* `construct` - creates new class throgh constructor.
15+
* `constructEmpty` - creates new empty class throgh constructor with all methods return null.
16+
* `copy` - copies object and redefines it's properties.
17+
18+
### Example
19+
20+
{% highlight php %}
21+
<?php
22+
use \Codeception\Util\Stub as Stub;
23+
24+
// create class instance with name set method 'save' redefined.
25+
$user = Stub::make('User', array('name' => 'davert', 'save' => function () { return true; }));
26+
27+
// create class instance with all empty methods (will return NULL)
28+
$user = Stub::makeEmpty('User', array('getName' => function () { return 'davert'; }));
29+
$user->save(); // is empty and returns NULL
30+
$user->getName(); // return 'davert'
31+
32+
// create class with empty methods except one
33+
$user = Stub::makeEmptyExcept('User', 'getName', array('name' => 'davert'));
34+
$user->save(); // is empty and returns NULL
35+
$user->getName(); // returns 'davert'
36+
37+
// create class instance through constructor
38+
// second parameter is array, it's values will be passed to constructor.
39+
40+
// similar to $user = new User($con, $is_new);
41+
$user = Stub::construct('User', array($con, $is_new), array('name' => 'davert'));
42+
43+
// similar is constructEmpty
44+
$user = Stub::constructEmpty('User', array($con, $is_new), array('getName' => function () { return 'davert'; }));
45+
46+
// and constructEmptyExcept
47+
$user = Stub::constructEmptyExcept('User', 'getName', array($con, $is_new), array('name' => 'davert'));
48+
49+
// copy and redefine class instance
50+
// can act with regular objects, not only stubs
51+
$user->getName(); // returns 'davert'
52+
$user2 = Stub::copy($user, array('name' => 'davert2'));
53+
$user->getName(); // returns 'davert2'
54+
?>
55+
{% endhighlight %}
56+

0 commit comments

Comments
 (0)