Skip to content

Commit 539200a

Browse files
committed
cool font added
1 parent 047c003 commit 539200a

File tree

3 files changed

+66
-65
lines changed

3 files changed

+66
-65
lines changed

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
markdown: rdiscount
1+
markdown: redcarpet
22
pygments: true
33
permalink: /:month-:day-:year/:title.html

css/syntax.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ code.yaml .nv {color: #fff;}
3232
}
3333

3434
code {
35-
color: white;
36-
background: #222;
35+
font-family: "Bitstream Vera Sans Mono",monospace;
36+
color: #222;
37+
padding: 5px;
38+
background: white;
3739
}

docs/03-Modules.markdown

Lines changed: 61 additions & 62 deletions
Original file line numberDiff line numberDiff 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+
66
# Modules
77

88
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
1212

1313
Let's look at this test.
1414

15-
``
15+
``
1616

17-
{% highlight php %}
17+
{% highlight php %}
1818
<?php
1919
2020
$I = new TestGuy($scenario);
2121
$I->amOnPage('/');
2222
$I->see('Hello');
2323
$I->seeInDatabase('users', array('id' => 1));
2424
$I->seeFileFound('running.lock');
25-
?>
25+
?>
2626
{% endhighlight %}
27-
``
27+
``
2828

2929

3030
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.
3131

3232
Modules are attached to Guy-classes in suite config.
3333
For current example in 'tests/functional.suite.yml' we should see.
3434

35-
``
35+
``
3636

3737
class_name: TestGuy
3838
modules:
3939
enabled: [Symfony1, Db, Filesystem]
40-
``
40+
``
4141

4242

4343
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.
6666

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

69-
``
69+
``
7070

71-
{% highlight php %}
71+
{% highlight php %}
7272
<?php
7373
namespace Codeception\Module;
7474
// here you can define custom functions for TestGuy
@@ -78,9 +78,9 @@ require_once 'PHPUnit/Framework/Assert/Functions.php';
7878
class TestHelper extends \Codeception\Module
7979
{
8080
}
81-
?>
81+
?>
8282
{% endhighlight %}
83-
``
83+
``
8484

8585

8686
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
8989

9090
Name your assertions like:
9191

92-
``
92+
``
9393

9494
seePageReloaded();
9595
seeClassIsLoaded($classname);
9696
dontSeeUserExist($user);
97-
``
97+
``
9898

9999
And then use them in your tests:
100100

101-
``
101+
``
102102

103-
{% highlight php %}
103+
{% highlight php %}
104104
<?php
105105
$I = new TestGuy($scenario);
106106
$I->seePageReloaded();
107107
$I->seeClassIsLoaded('TestGuy');
108108
$I->dontSeeUserExist($user);
109-
?>
109+
?>
110110
{% endhighlight %}
111-
``
111+
``
112112

113113

114114
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
117117
You can define asserts by using assertXXX functions, from 'PHPUnit/Framework/Assert/Functions.php' file.
118118
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.
119119

120-
``
120+
``
121121

122-
{% highlight php %}
122+
{% highlight php %}
123123
<?php
124124
125125
function seeClassExist($class)
@@ -128,30 +128,30 @@ function seeClassExist($class)
128128
// or
129129
\PHPUnit_Framework_Assert::assertTrue(class_exists($class));
130130
}
131-
?>
131+
?>
132132
{% endhighlight %}
133-
``
133+
``
134134

135135

136136
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.
137137

138-
``
138+
``
139139

140-
{% highlight php %}
140+
{% highlight php %}
141141
<?php
142142
143143
$this->assert(array('Equals',$int,3));
144144
$this->assertNot(array('internalType',$int,'bool'));
145145
$this->assert(array('Contains', array(3,5,9), 3));
146-
?>
146+
?>
147147
{% endhighlight %}
148-
``
148+
``
149149

150150
Let's see how define both 'see' and don't see action without code duplication.
151151

152-
``
152+
``
153153

154-
{% highlight php %}
154+
{% highlight php %}
155155
<?php
156156
157157
public function seeClassExist($class)
@@ -168,9 +168,9 @@ protected function proceedSeeClassExist($class)
168168
{
169169
return array('True',get_class($class));
170170
}
171-
?>
171+
?>
172172
{% endhighlight %}
173-
``
173+
``
174174

175175
For dontSeeClassExist, the 'assertFalse' will be called.
176176

@@ -188,19 +188,19 @@ Each modules can interact with each other by getModule method. Please, note that
188188

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

191-
``
191+
``
192192

193-
{% highlight php %}
193+
{% highlight php %}
194194
<?php
195195
196196
function reconnectToDatabase() {
197197
$dbh = $this->getModule('Db')->dbh;
198198
$dbh->close();
199199
$dbh->open();
200200
}
201-
?>
201+
?>
202202
{% endhighlight %}
203-
``
203+
``
204204

205205
By using getModule function you get access to all public methods and properties of module.
206206
The dbh property was defined public specially to be avaible to other modules.
@@ -209,9 +209,9 @@ That may be also useful if you need to perform sequence of actions taken from ot
209209

210210
For example:
211211

212-
``
212+
``
213213

214-
{% highlight php %}
214+
{% highlight php %}
215215
<?php
216216
function seeConfigFilesCreated()
217217
{
@@ -220,9 +220,9 @@ function seeConfigFilesCreated()
220220
$filesystem->openFile('codeception.yml');
221221
$filesystem->seeInFile('paths');
222222
}
223-
?>
223+
?>
224224
{% endhighlight %}
225-
``
225+
``
226226

227227

228228
### Hooks
@@ -235,9 +235,9 @@ All hooks are defined in \Codeception\Module
235235

236236
Here are they listed. You are free to redefine them in you module.
237237

238-
``
238+
``
239239

240-
{% highlight php %}
240+
{% highlight php %}
241241
<?php
242242
243243
// HOOK: used after configuration is loaded
@@ -267,9 +267,9 @@ Here are they listed. You are free to redefine them in you module.
267267
// HOOK: on fail
268268
public function _failed(\Codeception\TestCase $test, $fail) {
269269
}
270-
?>
270+
?>
271271
{% endhighlight %}
272-
``
272+
``
273273

274274

275275
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.
@@ -285,64 +285,63 @@ Thus, modules are not a black boxes, they are trying to show you what is happeni
285285
To print additional information use debug amd debugSection methods of module.
286286
Here is the sample how it works for PhpBrowser:
287287

288-
``
288+
``
289289

290-
{% highlight php %}
290+
{% highlight php %}
291291
<?php
292292
$this->debug('Request ('.$method.'): '.$uri.' '. json_encode($params));
293293
$browser->request($method, $uri, $params);
294294
$this->debug('Response code: '.$this->session->getStatusCode());
295-
?>
295+
?>
296296
{% endhighlight %}
297-
``
297+
``
298298

299299

300300
The test running with PhpBrowser module in debug mode will print something like this:
301301

302-
``
302+
``
303303

304304
I click "All pages"
305305
* Request (GET) http://localhost/pages {}
306306
* Response code: 200
307-
``
307+
``
308308

309309

310310
### Configuration
311311

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

315-
``
315+
``
316316

317-
{% highlight php %}
317+
{% highlight php %}
318318
<?php
319319
class Db extends \Codeception\Module {
320320
protected $requiredFields = array('dsn', 'user', 'password');
321-
?>
321+
?>
322322
{% endhighlight %}
323-
``
323+
``
324324

325325
Next time you start suite without this values set, an exception will be thrown.
326326

327327
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.
328328

329-
``
329+
``
330330

331-
{% highlight php %}
331+
{% highlight php %}
332332
<?php
333333
class Selenium extends \Codeception\Util\MinkJS
334334
{
335335
protected $requiredFields = array('browser', 'url');
336336
protected $config = array('host' => '127.0.0.1', 'port' => '4444');
337-
?>
337+
?>
338338
{% endhighlight %}
339-
``
339+
``
340340

341341

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

344-
``
345-
344+
`
346345
modules:
347346
enabled:
348347
- Selenium
@@ -354,7 +353,7 @@ modules:
354353
Db:
355354
cleanup: false
356355
repopulate: false
357-
``
356+
`
358357

359358

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

0 commit comments

Comments
 (0)