You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/03-Modules.markdown
+61-62Lines changed: 61 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
---
2
-
layout: page
3
-
title: Codeception - Documentation
4
-
---
5
-
1
+
---
2
+
layout: page
3
+
title: Codeception - Documentation
4
+
---
5
+
6
6
# Modules
7
7
8
8
Codeception uses modularity to create comfortable testing environment for every test suite you write.
@@ -12,32 +12,32 @@ All actions and assertions that can be performed by Guy object in class are defi
12
12
13
13
Let's look at this test.
14
14
15
-
``
15
+
``
16
16
17
-
{% highlight php %}
17
+
{% highlight php %}
18
18
<?php
19
19
20
20
$I = new TestGuy($scenario);
21
21
$I->amOnPage('/');
22
22
$I->see('Hello');
23
23
$I->seeInDatabase('users', array('id' => 1));
24
24
$I->seeFileFound('running.lock');
25
-
?>
25
+
?>
26
26
{% endhighlight %}
27
-
``
27
+
``
28
28
29
29
30
30
It can operate with different entities: the web page can be loaded with Symfony1 module, the database assertion uses Db module, and file state can be checked with Filesystem module.
31
31
32
32
Modules are attached to Guy-classes in suite config.
33
33
For current example in 'tests/functional.suite.yml' we should see.
34
34
35
-
``
35
+
``
36
36
37
37
class_name: TestGuy
38
38
modules:
39
39
enabled: [Symfony1, Db, Filesystem]
40
-
``
40
+
``
41
41
42
42
43
43
The TestGuy class has it's methods defined in modules. Actually, it doesn't contain any of them, but acts as a proxy for them. It knows which module executes this action and passes parameters into it. To make your IDE see all methods of TestGuy listed, you use the 'build' command. It generates definition of TestGuy class by copying signatures from modules.
@@ -66,9 +66,9 @@ It's good idea to define missing actions or assertion commands in helpers.
66
66
67
67
Let's say we are going to extend TestHelper class. By default it's linked with a TestGuy class and functional test suite.
68
68
69
-
``
69
+
``
70
70
71
-
{% highlight php %}
71
+
{% highlight php %}
72
72
<?php
73
73
namespace Codeception\Module;
74
74
// here you can define custom functions for TestGuy
As for actions everything is quite simple. Every action you define is a public function. Write down any public method, run 'build' command, and you will see this function added into TestGuy class. Still, public methods prefixed by '_' are treated as hidden and won't be added you your Guy class.
@@ -89,26 +89,26 @@ Assertions are a bit tricky. First of all it's recommended to prefix all your as
89
89
90
90
Name your assertions like:
91
91
92
-
``
92
+
``
93
93
94
94
seePageReloaded();
95
95
seeClassIsLoaded($classname);
96
96
dontSeeUserExist($user);
97
-
``
97
+
``
98
98
99
99
And then use them in your tests:
100
100
101
-
``
101
+
``
102
102
103
-
{% highlight php %}
103
+
{% highlight php %}
104
104
<?php
105
105
$I = new TestGuy($scenario);
106
106
$I->seePageReloaded();
107
107
$I->seeClassIsLoaded('TestGuy');
108
108
$I->dontSeeUserExist($user);
109
-
?>
109
+
?>
110
110
{% endhighlight %}
111
-
``
111
+
``
112
112
113
113
114
114
Every 'see' or 'dontSee' function requires at least one assert. Codeception uses PHPUnit assertions.
@@ -117,9 +117,9 @@ Every 'see' or 'dontSee' function requires at least one assert. Codeception uses
117
117
You can define asserts by using assertXXX functions, from 'PHPUnit/Framework/Assert/Functions.php' file.
118
118
In case your application falls into conflict with one of this functions, you can use PHPUnit static methods from class PHPUnit_Framework_Assert to define asserts.
119
119
120
-
``
120
+
``
121
121
122
-
{% highlight php %}
122
+
{% highlight php %}
123
123
<?php
124
124
125
125
function seeClassExist($class)
@@ -128,30 +128,30 @@ function seeClassExist($class)
Each module has special $this->assert and $this->assertNot methods. They take the same arguments and are useful if you need to define both positive and negative assertions in your module. This functions take an array as parameter, where the first value of array is the name of PHPUnit assert function.
Next time you start suite without this values set, an exception will be thrown.
326
326
327
327
For the optional parameters you should have default values set. The $config property is used to define optional parameters as well as their values. In Seleinum module we use default Selenium Server address and port.
0 commit comments