2121 *
2222 * ``` php
2323 * <?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
2827 * ```
2928 *
3029 * Example:
3332 * <?php
3433 * $I->wantTo('create article');
3534 * $I->click('New Article');
36- * $I->fillField('Title', 'Article'. sq('name '));
35+ * $I->fillField('Title', sq('Article '));
3736 * $I->fillField('Body', 'Demo article with Lorem Ipsum');
3837 * $I->click('save');
39- * $I->see('Article'.sq('name') ,'#articles')
40- * ?>
38+ * $I->see(sq('Article') ,'#articles')
4139 * ```
4240 *
4341 * Populating Database:
4644 * <?php
4745 *
4846 * 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');
5048 * }
5149 * ?>
5250 * ```
5957 * {
6058 * public function createUser(AcceptanceTester $I)
6159 * {
62- * $I->createUser('email' . sqs('user') . '@mailserver.com', sqs('login'), sqs('pwd'));
60+ * $I->createUser(sqs('user') . '@mailserver.com', sqs('login'), sqs('pwd'));
6361 * }
6462 *
6563 * public function checkEmail(AcceptanceTester $I)
6664 * {
67- * $I->seeInEmailTo('email' . sqs('user') . '@mailserver.com', sqs('login'));
65+ * $I->seeInEmailTo(sqs('user') . '@mailserver.com', sqs('login'));
6866 * }
6967 *
7068 * public function removeUser(AcceptanceTester $I)
7169 * {
72- * $I->removeUser('email' . sqs('user') . '@mailserver.com');
70+ * $I->removeUser(sqs('user') . '@mailserver.com');
7371 * }
7472 * }
7573 * ?>
7674 * ```
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+ * ```
7799 */
78100class Sequence extends CodeceptionModule
79101{
80102 public static $ hash = [];
81103 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+ }
82112
83113 public function _after (TestInterface $ t )
84114 {
@@ -93,7 +123,6 @@ public function _afterSuite()
93123
94124if (!function_exists ('sq ' ) && !function_exists ('sqs ' )) {
95125 require_once __DIR__ . '/../Util/sq.php ' ;
96- require_once __DIR__ . '/../Util/sqs.php ' ;
97126} else {
98127 throw new ModuleException ('Codeception\Module\Sequence ' , "function 'sq' and 'sqs' already defined " );
99128}
0 commit comments