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