Skip to content

Commit 047c003

Browse files
committed
=auto-updated documentation
1 parent e13fb26 commit 047c003

11 files changed

Lines changed: 268 additions & 127 deletions

docs/01-Introduction.markdown

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Please, note, that **any site** can be covered with acceptance tests. Even you u
2929

3030
#### Sample acceptance test
3131

32-
``
32+
``
33+
3334
{% highlight php %}
3435
<?php
3536
$I = new TestGuy($scenario);
@@ -38,7 +39,8 @@ $I->click('Sign Up');
3839
$I->submitForm('#signup', array('username' => 'MilesDavis', 'email' => 'miles@davis.com'));
3940
$I->see('Thank you for Signing Up!');
4041

41-
``
42+
``
43+
4244

4345
#### Pros
4446

@@ -65,7 +67,8 @@ Codeceptance provides connectors to several popular PHP frameworks, but you can
6567

6668
#### Sample functional test
6769

68-
``
70+
``
71+
6972
{% highlight php %}
7073
<?php
7174
$I = new TestGuy($scenario);
@@ -76,7 +79,8 @@ $I->see('Thank you for Signing Up!');
7679
$I->seeEmailSent('miles@davis.com', 'Thank you for registration');
7780
$I->seeInDatabase('users', array('email' => 'miles@davis.com'));
7881

79-
``
82+
``
83+
8084

8185
#### Pros
8286

@@ -103,7 +107,8 @@ But Codeception provides some good tools to have your unit tests simplier and cl
103107

104108
#### Sample integration test
105109

106-
``
110+
``
111+
107112
{% highlight php %}
108113
<?php
109114
// we are testing public method of User class.
@@ -117,7 +122,8 @@ $I->executeTestedMethodOn($unit, 1, array('username' => 'miles'));
117122
$I->seeMethodInvoked($unit, 'save');
118123
$I->seeInDatabase('users', array('id' => 1, 'username' => 'miles'));
119124

120-
``
125+
``
126+
121127

122128
#### Pros
123129

docs/03-Modules.markdown

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ All actions and assertions that can be performed by Guy object in class are defi
1212

1313
Let's look at this test.
1414

15-
``
15+
``
16+
1617
{% highlight php %}
1718
<?php
1819
@@ -23,18 +24,21 @@ $I->seeInDatabase('users', array('id' => 1));
2324
$I->seeFileFound('running.lock');
2425
?>
2526
{% endhighlight %}
26-
``
27+
``
28+
2729

2830
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.
2931

3032
Modules are attached to Guy-classes in suite config.
3133
For current example in 'tests/functional.suite.yml' we should see.
3234

33-
``
35+
``
36+
3437
class_name: TestGuy
3538
modules:
3639
enabled: [Symfony1, Db, Filesystem]
37-
``
40+
``
41+
3842

3943
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.
4044

@@ -62,7 +66,8 @@ It's good idea to define missing actions or assertion commands in helpers.
6266

6367
Let's say we are going to extend TestHelper class. By default it's linked with a TestGuy class and functional test suite.
6468

65-
``
69+
``
70+
6671
{% highlight php %}
6772
<?php
6873
namespace Codeception\Module;
@@ -75,22 +80,26 @@ class TestHelper extends \Codeception\Module
7580
}
7681
?>
7782
{% endhighlight %}
78-
``
83+
``
84+
7985

8086
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.
8187

8288
Assertions are a bit tricky. First of all it's recommended to prefix all your assert actions with 'see', or 'dontSee'. In Codeception philosophy all tests are performed by humans, i.e. guys. The expected result they see (or they don't) is what we use for assertion.
8389

8490
Name your assertions like:
8591

86-
``
92+
``
93+
8794
seePageReloaded();
8895
seeClassIsLoaded($classname);
8996
dontSeeUserExist($user);
90-
``
97+
``
98+
9199
And then use them in your tests:
92100

93-
``
101+
``
102+
94103
{% highlight php %}
95104
<?php
96105
$I = new TestGuy($scenario);
@@ -99,15 +108,17 @@ $I->seeClassIsLoaded('TestGuy');
99108
$I->dontSeeUserExist($user);
100109
?>
101110
{% endhighlight %}
102-
``
111+
``
112+
103113

104114
Every 'see' or 'dontSee' function requires at least one assert. Codeception uses PHPUnit assertions.
105115

106116
### Assertions
107117
You can define asserts by using assertXXX functions, from 'PHPUnit/Framework/Assert/Functions.php' file.
108118
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.
109119

110-
``
120+
``
121+
111122
{% highlight php %}
112123
<?php
113124
@@ -119,11 +130,13 @@ function seeClassExist($class)
119130
}
120131
?>
121132
{% endhighlight %}
122-
``
133+
``
134+
123135

124136
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.
125137

126-
``
138+
``
139+
127140
{% highlight php %}
128141
<?php
129142
@@ -132,10 +145,12 @@ $this->assertNot(array('internalType',$int,'bool'));
132145
$this->assert(array('Contains', array(3,5,9), 3));
133146
?>
134147
{% endhighlight %}
135-
``
148+
``
149+
136150
Let's see how define both 'see' and don't see action without code duplication.
137151

138-
``
152+
``
153+
139154
{% highlight php %}
140155
<?php
141156
@@ -155,7 +170,8 @@ protected function proceedSeeClassExist($class)
155170
}
156171
?>
157172
{% endhighlight %}
158-
``
173+
``
174+
159175
For dontSeeClassExist, the 'assertFalse' will be called.
160176

161177
### Resolving Collisions
@@ -172,7 +188,8 @@ Each modules can interact with each other by getModule method. Please, note that
172188

173189
Let's imagine we are writing module which reconnects to database. It's supposed to use the dbh connection value from Db module.
174190

175-
``
191+
``
192+
176193
{% highlight php %}
177194
<?php
178195
@@ -183,15 +200,17 @@ function reconnectToDatabase() {
183200
}
184201
?>
185202
{% endhighlight %}
186-
``
203+
``
204+
187205
By using getModule function you get access to all public methods and properties of module.
188206
The dbh property was defined public specially to be avaible to other modules.
189207

190208
That may be also useful if you need to perform sequence of actions taken from other modules.
191209

192210
For example:
193211

194-
``
212+
``
213+
195214
{% highlight php %}
196215
<?php
197216
function seeConfigFilesCreated()
@@ -203,7 +222,8 @@ function seeConfigFilesCreated()
203222
}
204223
?>
205224
{% endhighlight %}
206-
``
225+
``
226+
207227

208228
### Hooks
209229

@@ -215,7 +235,8 @@ All hooks are defined in \Codeception\Module
215235

216236
Here are they listed. You are free to redefine them in you module.
217237

218-
``
238+
``
239+
219240
{% highlight php %}
220241
<?php
221242
@@ -248,7 +269,8 @@ Here are they listed. You are free to redefine them in you module.
248269
}
249270
?>
250271
{% endhighlight %}
251-
``
272+
``
273+
252274

253275
Please, note, that methods with '_' prefix are not added to the Guy class. This allows them to be defined as public, but used for internal purposes.
254276

@@ -263,42 +285,49 @@ Thus, modules are not a black boxes, they are trying to show you what is happeni
263285
To print additional information use debug amd debugSection methods of module.
264286
Here is the sample how it works for PhpBrowser:
265287

266-
``
288+
``
289+
267290
{% highlight php %}
268291
<?php
269292
$this->debug('Request ('.$method.'): '.$uri.' '. json_encode($params));
270293
$browser->request($method, $uri, $params);
271294
$this->debug('Response code: '.$this->session->getStatusCode());
272295
?>
273296
{% endhighlight %}
274-
``
297+
``
298+
275299

276300
The test running with PhpBrowser module in debug mode will print something like this:
277301

278-
``
302+
``
303+
279304
I click "All pages"
280305
* Request (GET) http://localhost/pages {}
281306
* Response code: 200
282-
``
307+
``
308+
283309

284310
### Configuration
285311

286312
Modules can be configured from suite config file, or globally from codeception.yml.
287313
Mandatory parameters should be defined in $$requiredFields property of module class. Here how it is done in Db module
288314

289-
``
315+
``
316+
290317
{% highlight php %}
291318
<?php
292319
class Db extends \Codeception\Module {
293320
protected $requiredFields = array('dsn', 'user', 'password');
294321
?>
295322
{% endhighlight %}
296-
``
323+
``
324+
297325
Next time you start suite without this values set, an exception will be thrown.
298326

299327
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.
300328

301-
``
329+
``
330+
302331
{% highlight php %}
303332
<?php
304333
class Selenium extends \Codeception\Util\MinkJS
@@ -307,11 +336,13 @@ class Selenium extends \Codeception\Util\MinkJS
307336
protected $config = array('host' => '127.0.0.1', 'port' => '4444');
308337
?>
309338
{% endhighlight %}
310-
``
339+
``
340+
311341

312342
The host and port parameter can be redefined in suite config. Values are set in 'modules:config' section of configuration file.
313343

314-
``
344+
``
345+
315346
modules:
316347
enabled:
317348
- Selenium
@@ -323,7 +354,8 @@ modules:
323354
Db:
324355
cleanup: false
325356
repopulate: false
326-
``
357+
``
358+
327359

328360
Optional and mandatory parameters can be accessed through the $config property. Use $this->config['parameter'] to get it's value.
329361

docs/04-AcceptanceTesting.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ We call him a WebGuy, as he uses web browser to open your site and test it's beh
1313
Writing Codeception tests is just the same as describing actions you perform on a site. Only the basic knowlegde of HTML and PHP is required for wrinig such tests.
1414

1515
``
16+
1617
{% highlight php %}
1718
<?php
1819
$I = new WebGuy($scenario);
@@ -24,13 +25,14 @@ $I->click('LOGIN');
2425
$I->see('Welcome, Davert!');
2526
?>
2627
{% endhighlight %}
27-
``
28+
{% endhighlight %}
2829

2930
With no knowledge in PHP or HTML you can still read this scenario. Or not?
3031
Well, if you have problems reading this, Codeception can convert this scenario into text written mostly in native English:
3132

3233
``
3334

35+
3436
I WANT TO SIGN IN
3537
I am on page '/login'
3638
I fill field ['signin[username]', 'davert']
@@ -40,6 +42,7 @@ I see 'Welcome, Davert!'
4042

4143
``
4244

45+
4346
This scenario can be performed in either simple PHP browser or within the browser through Selenium (also Sahi or ZombieJS).
4447

4548
## Getting Started

0 commit comments

Comments
 (0)