commit | author | age
|
2207d6
|
1 |
# Sequence |
W |
2 |
|
|
3 |
|
|
4 |
Sequence solves data cleanup issue in alternative way. |
|
5 |
Instead cleaning up the database between tests, |
|
6 |
you can use generated unique names, that should not conflict. |
|
7 |
When you create article on a site, for instance, you can assign it a unique name and then check it. |
|
8 |
|
|
9 |
This module has no actions, but introduces a function `sq` for generating unique sequences within test and |
|
10 |
`sqs` for generating unique sequences across suite. |
|
11 |
|
|
12 |
### Usage |
|
13 |
|
|
14 |
Function `sq` generates sequence, the only parameter it takes, is id. |
|
15 |
You can get back to previously generated sequence using that id: |
|
16 |
|
|
17 |
``` php |
|
18 |
<?php |
|
19 |
sq('post1'); // post1_521fbc63021eb |
|
20 |
sq('post2'); // post2_521fbc6302266 |
|
21 |
sq('post1'); // post1_521fbc63021eb |
|
22 |
``` |
|
23 |
|
|
24 |
Example: |
|
25 |
|
|
26 |
``` php |
|
27 |
<?php |
|
28 |
$I->wantTo('create article'); |
|
29 |
$I->click('New Article'); |
|
30 |
$I->fillField('Title', sq('Article')); |
|
31 |
$I->fillField('Body', 'Demo article with Lorem Ipsum'); |
|
32 |
$I->click('save'); |
|
33 |
$I->see(sq('Article') ,'#articles') |
|
34 |
``` |
|
35 |
|
|
36 |
Populating Database: |
|
37 |
|
|
38 |
``` php |
|
39 |
<?php |
|
40 |
|
|
41 |
for ($i = 0; $i<10; $i++) { |
|
42 |
$I->haveInDatabase('users', array('login' => sq("user$i"), 'email' => sq("user$i").'@email.com'); |
|
43 |
} |
|
44 |
?> |
|
45 |
``` |
|
46 |
|
|
47 |
Cest Suite tests: |
|
48 |
|
|
49 |
``` php |
|
50 |
<?php |
|
51 |
class UserTest |
|
52 |
{ |
|
53 |
public function createUser(AcceptanceTester $I) |
|
54 |
{ |
|
55 |
$I->createUser(sqs('user') . '@mailserver.com', sqs('login'), sqs('pwd')); |
|
56 |
} |
|
57 |
|
|
58 |
public function checkEmail(AcceptanceTester $I) |
|
59 |
{ |
|
60 |
$I->seeInEmailTo(sqs('user') . '@mailserver.com', sqs('login')); |
|
61 |
} |
|
62 |
|
|
63 |
public function removeUser(AcceptanceTester $I) |
|
64 |
{ |
|
65 |
$I->removeUser(sqs('user') . '@mailserver.com'); |
|
66 |
} |
|
67 |
} |
|
68 |
?> |
|
69 |
``` |
|
70 |
|
|
71 |
### Config |
|
72 |
|
|
73 |
By default produces unique string with param as a prefix: |
|
74 |
|
|
75 |
``` |
|
76 |
sq('user') => 'user_876asd8as87a' |
|
77 |
``` |
|
78 |
|
|
79 |
This behavior can be configured using `prefix` config param. |
|
80 |
|
|
81 |
Old style sequences: |
|
82 |
|
|
83 |
```yaml |
|
84 |
Sequence: |
|
85 |
prefix: '_' |
|
86 |
``` |
|
87 |
|
|
88 |
Using id param inside prefix: |
|
89 |
|
|
90 |
```yaml |
|
91 |
Sequence: |
|
92 |
prefix: '{id}.' |
|
93 |
``` |
|
94 |
|
|
95 |
## Actions |
|
96 |
|
|
97 |
<p> </p><div class="alert alert-warning">Module reference is taken from the source code. <a href="https://github.com/Codeception/Codeception/tree/2.5/src/Codeception/Module/Sequence.php">Help us to improve documentation. Edit module reference</a></div> |