21
21
*
22
22
* ``` php
23
23
* <?php
24
- * 'post'.sq(1); // post_521fbc63021eb
25
- * 'post'.sq(2); // post_521fbc6302266
26
- * 'post'.sq(1); // post_521fbc63021eb
27
- * ?>
24
+ * sq('post1'); // post1_521fbc63021eb
25
+ * sq('post2'); // post2_521fbc6302266
26
+ * sq('post1'); // post1_521fbc63021eb
28
27
* ```
29
28
*
30
29
* Example:
33
32
* <?php
34
33
* $I->wantTo('create article');
35
34
* $I->click('New Article');
36
- * $I->fillField('Title', 'Article'. sq('name '));
35
+ * $I->fillField('Title', sq('Article '));
37
36
* $I->fillField('Body', 'Demo article with Lorem Ipsum');
38
37
* $I->click('save');
39
- * $I->see('Article'.sq('name') ,'#articles')
40
- * ?>
38
+ * $I->see(sq('Article') ,'#articles')
41
39
* ```
42
40
*
43
41
* Populating Database:
46
44
* <?php
47
45
*
48
46
* for ($i = 0; $i<10; $i++) {
49
- * $I->haveInDatabase('users', array('login' => 'user'. sq($i ), 'email' => 'user'. sq($i ).'@email.com');
47
+ * $I->haveInDatabase('users', array('login' => sq("user$i" ), 'email' => sq("user$i" ).'@email.com');
50
48
* }
51
49
* ?>
52
50
* ```
59
57
* {
60
58
* public function createUser(AcceptanceTester $I)
61
59
* {
62
- * $I->createUser('email' . sqs('user') . '@mailserver.com', sqs('login'), sqs('pwd'));
60
+ * $I->createUser(sqs('user') . '@mailserver.com', sqs('login'), sqs('pwd'));
63
61
* }
64
62
*
65
63
* public function checkEmail(AcceptanceTester $I)
66
64
* {
67
- * $I->seeInEmailTo('email' . sqs('user') . '@mailserver.com', sqs('login'));
65
+ * $I->seeInEmailTo(sqs('user') . '@mailserver.com', sqs('login'));
68
66
* }
69
67
*
70
68
* public function removeUser(AcceptanceTester $I)
71
69
* {
72
- * $I->removeUser('email' . sqs('user') . '@mailserver.com');
70
+ * $I->removeUser(sqs('user') . '@mailserver.com');
73
71
* }
74
72
* }
75
73
* ?>
76
74
* ```
75
+ *
76
+ * ### Config
77
+ *
78
+ * By default produces unique string with param as a prefix:
79
+ *
80
+ * ```
81
+ * sq('user') => 'user_876asd8as87a'
82
+ * ```
83
+ *
84
+ * This behavior can be configured using `prefix` config param.
85
+ *
86
+ * Old style sequences:
87
+ *
88
+ * ```yaml
89
+ * Sequence:
90
+ * prefix: '_'
91
+ * ```
92
+ *
93
+ * Using id param inside prefix:
94
+ *
95
+ * ```yaml
96
+ * Sequence:
97
+ * prefix: '{id}.'
98
+ * ```
77
99
*/
78
100
class Sequence extends CodeceptionModule
79
101
{
80
102
public static $ hash = [];
81
103
public static $ suiteHash = [];
104
+ public static $ prefix = '' ;
105
+
106
+ protected $ config = ['prefix ' => '{id}_ ' ];
107
+
108
+ public function _initialize ()
109
+ {
110
+ static ::$ prefix = $ this ->config ['prefix ' ];
111
+ }
82
112
83
113
public function _after (TestInterface $ t )
84
114
{
@@ -93,7 +123,6 @@ public function _afterSuite()
93
123
94
124
if (!function_exists ('sq ' ) && !function_exists ('sqs ' )) {
95
125
require_once __DIR__ . '/../Util/sq.php ' ;
96
- require_once __DIR__ . '/../Util/sqs.php ' ;
97
126
} else {
98
127
throw new ModuleException ('Codeception\Module\Sequence ' , "function 'sq' and 'sqs' already defined " );
99
128
}
0 commit comments